题目
思路
反转字符串,不能利用库函数。也可以利用对撞指针的方式,两个指针的值互换位置。
代码
class Solution(object):
def reverseString(self, s):
"""
:type s: List[str]
:rtype: None Do not return anything, modify s in-place instead.
"""
i,j = 0,len(s)-1
while i < j:
s[i],s[j] = s[j],s[i] # python中互换数组中两个元素便捷写法!!
i += 1
j -= 1
return