标签:pre pytho write test while 简单 简单的 sub desc
1 class Solution: 2 def LeftRotateString(self, s, n): 3 # write code here 4 return s[n:]+s[:n]
方法二:
1 class Solution: 2 def LeftRotateString(self, s, n): 3 # write code here 4 if s == "": 5 return "" 6 s=list(s) 7 self.reverse(s,0,n-1) 8 self.reverse(s,n,len(s)-1) 9 self.reverse(s,0,len(s)-1) 10 return ‘‘.join(s) 11 def reverse(self,s,low,high): 12 while low < high: 13 s[low],s[high]=s[high],s[low] 14 low+=1 15 high-=1
2019-12-25 19:25:09
标签:pre pytho write test while 简单 简单的 sub desc
原文地址:https://www.cnblogs.com/NPC-assange/p/12098513.html