-
#字符串切片 拼接
class Solution:
def reverseLeftWords(self, s: str, n: int) -> str:
res=s[n:]+s[:n]
return res
- #遍历 用字符串拼接
class Solution:
def reverseLeftWords(self, s: str, n: int) -> str:
res=''
for i in range(n,len(s)):
res+=s[i]
for i in range(n):
res+=s[i]
return res
- # 遍历 用列表 最后join拼接转成字符串
class Solution: def reverseLeftWords(self, s: str, n: int) -> str: res=[] for i in range(n,len(s)): res.append(s[i]) for i in range(n): res.append(s[i]) return ''.join(res)