LeetCode | 344.反转字符串

在这里插入图片描述
设置头尾两个指针,依靠中间变量temp交换头尾指针所指元素,头指针后移,尾指针前移,直到头尾指针重合或者头指针在尾指针后面一个元素

class Solution(object):
    def reverseString(self, s):
        """
        :type s: List[str]
        :rtype: None Do not return anything, modify s in-place instead.
        """
        temp = 0
        i,j = 0,len(s)-1
        while i<j:
            temp = s[i]
            s[i] = s[j]
            s[j] = temp
            i += 1
            j -= 1
            if j == i-1 or i == j:
                return s

class Solution(object):
    def reverseString(self, s):
        """
        :type s: List[str]
        :rtype: None Do not return anything, modify s in-place instead.
        """
        return s.reverse()

在这里插入图片描述

相关推荐

  1. leetcode344. 字符串

    2024-06-17 07:00:05       65 阅读
  2. LeetCode344 -字符串

    2024-06-17 07:00:05       35 阅读
  3. LeetCode 344.字符串

    2024-06-17 07:00:05       39 阅读
  4. leetcode344、541——字符串

    2024-06-17 07:00:05       34 阅读
  5. Leetcode的AC指南 —— 字符串344. 字符串

    2024-06-17 07:00:05       68 阅读
  6. 字符串|344.字符串

    2024-06-17 07:00:05       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-17 07:00:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-17 07:00:05       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-17 07:00:05       82 阅读
  4. Python语言-面向对象

    2024-06-17 07:00:05       91 阅读

热门阅读

  1. QSharedMemory使用详解

    2024-06-17 07:00:05       27 阅读
  2. Qt 实战(4)信号与槽 | 4.3、信号连接信号

    2024-06-17 07:00:05       28 阅读
  3. 跨域资源共享(CORS)问题与解决方案

    2024-06-17 07:00:05       28 阅读
  4. wxml与标准的html的异同?

    2024-06-17 07:00:05       30 阅读
  5. 3.1. 马氏链-马氏链的定义和示例

    2024-06-17 07:00:05       27 阅读
  6. Android基础-JNI

    2024-06-17 07:00:05       24 阅读
  7. 一个简单的UDP客户端和服务端的完整C++示例

    2024-06-17 07:00:05       37 阅读
  8. 学习vite的核心原理

    2024-06-17 07:00:05       27 阅读
  9. Flutter学习(一)

    2024-06-17 07:00:05       30 阅读
  10. 【websocket】怎么终止websocket断开重连

    2024-06-17 07:00:05       30 阅读
  11. 【Git】撤销远程仓库的提交(push)

    2024-06-17 07:00:05       38 阅读
  12. cbam+lstm代码预测

    2024-06-17 07:00:05       22 阅读
  13. vant的作用及其使用方法

    2024-06-17 07:00:05       33 阅读
  14. 大数据开发语言Scala入门

    2024-06-17 07:00:05       32 阅读