** 344.反轉字串**
class Solution:
def reverseString(self, s: List[str]) -> None:
left = 0
right = len(s)-1
while left < right:
temp = s[left]
s[left] = s[right]
s[right] = temp
left += 1
right -= 1
541. 反轉字串II
明天再寫一遍
def reverse_substring(text):
left, right = 0, len(text) - 1
while left < right:
text[left], text[right] = text[right], text[left]
left += 1
right -= 1
return text
res = list(s)
for cur in range(0, len(s), 2 * k):
res[cur: cur + k] = reverse_substring(res[cur: cur + k])
return ''.join(res)
卡碼網:54.替換數字
151.翻轉字串裡的單詞
思路:先全部reverse,再reverse每個單詞,之後刪除掉多餘的空格(用快慢指標,慢指標指向字母應該在的地方,快指標指向字母實際在的地方),resize這個句子
卡碼網:55.右旋轉字串