344.反转字符串
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
s[0:len(s)] = s[::-1]
541. 反转字符串II
class Solution:
def reverseStr(self, s: str, k: int) -> str:
result = list(s)
for i in range(0, len(result), 2*k):
temp = result[i:i+k]
result[i:i+k] = temp[::-1]
return ''.join(result)
151.翻转字符串里的单词
class Solution:
def reverseWords(self, s: str) -> str:
s = s.strip()
result = s.split()
print(result)
result[:] = result[::-1]
return " ".join(result)