classSolution:defreverseString(self, s: List[str])->None:"""
Do not return anything, modify s in-place instead.
"""
l =0
r =len(s)-1while l < r:
s[l], s[r]= s[r], s[l]
l +=1
r -=1
直接
classSolution:defreverseString(self, s: List[str])->None:"""
Do not return anything, modify s in-place instead.
"""
s[:]= s[::-1]
557. 反转字符串中的单词 III
先分开再反转
classSolution:defreverseWords(self, s:str)->str:return" ".join(word[::-1]for word in s.split(" "))