** 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.右旋转字符串
标签:卡码,right,cur,text,反转,字符串,left From: https://www.cnblogs.com/miramira/p/18100397