every blog every motto: You will never know unless you try
0. 前言
生活好难,再坚持坚持!
1. 字符串
1.1 题目
1.2
class Solution:
def reverseStr(self, s: str, k: int) -> str:
s = list(s)
if len(s) < k:
s = self.reverse(s)
elif len(s)>= k and len(s) < 2*k:
s[:k] = self.reverse(s[:k])
else:
s[:k] = self.reverse(s[:k])
s[2*k:]=self.reverseStr(s[2*k:],k)
return ''.join(s)
def reverse(self,strs:str):
strs = list(strs)
left,right = 0,len(strs) -1
while left < right:
strs[left],strs[right] = strs[right],strs[left]
left += 1
right -= 1
return strs
1.3
|