这道题非常简单,就是双指针问题的基础版,时间复杂度是O(N),空间复杂度是O(1)
class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ if s is None or len(s) <= 1: return s start, end = 0, len(s) - 1 while start < end: s[start], s[end] = s[end], s[start] start += 1 end -=1
原文:https://www.cnblogs.com/codingEskimo/p/12220197.html