Leetcode 344.反转字符串 python版本
思路
使用双指针,左边指针指向数组开头,右边指针指向末尾,每次交换俩指针所指的数组值,然后左指针自加1,右指针自减1
代码
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
left, right = 0, len(s)-1
while left < right:
s[left], s[right] = s[right], s[left]
left +=1
right -=1