跳过正文
  1. leetcode 题解/

344_反转字符串

·58 字·1 分钟

类型:字符串

    1. 反转字符串 💚

    https://leetcode-cn.com/problems/reverse-string/

    ❓ 原地翻转字符串。

    💡 双指针

    class Solution:
        def reverseString(self, s: List[str]) -> None:
            """
            Do not return anything, modify s in-place instead.
            """
            length = len(s)
            for i in range(length // 2):
                if s[i] == s[length - 1 - i]:
                    continue
                s[i], s[length - 1 - i] = s[length - 1 - i], s[i]

    时间复杂度:O(n),空间复杂度:O(1)