344 反转字符串
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
# method
left = 0
right = len(s) - 1
while (left < right):
temp = s[left]
s[left] = s[right]
s[right] = temp
left += 1
right -= 1
return s
# method 2
s[:] = s[::-1]
557 反转字符串中的单词Ⅲ
class Solution:
def reverseWords(self, s: str) -> str:
s_list = s.split()
res = []
for item in s_list:
item = item[::-1]
res.append(item)
return " ".join(res)