标签:join test string offer turn 序列 range 翻转 nbsp
翻转单词顺序列:
1 # -*- coding:utf-8 -*- 2 class Solution: 3 def ReverseSentence(self, s): 4 ary = s.split(‘ ‘) 5 for i in range(len(ary[::-1])): 6 ary[i] = ary[i][::-1] 7 print(ary[i]) 8 return " ".join(ary)[::-1] 9 # write code here
左旋转字符串:
1 # -*- coding:utf-8 -*- 2 class Solution: 3 def LeftRotateString(self, s, n): 4 lens = len(s) 5 if lens == 0: 6 return ‘‘ 7 if n > lens: 8 n = n % lens 9 t = s[n:] + s[:n] 10 return t 11 # write code here
标签:join test string offer turn 序列 range 翻转 nbsp
原文地址:https://www.cnblogs.com/asenyang/p/11025040.html