https://www.lintcode.com/problem/8/?utm_source=sc-zhihuzl-swj0608
这个题目需要在原列表中操作,刚开始有点懵,然后想想列表的定义,最终还是解决。
class Solution:
"""
@param str: An array of char
@param offset: An integer
@return: nothing
"""
def rotateString(self, str, offset):
# write your code here
if len(str)==0:
return
off_new = offset%len(str)
if off_new==0:
return str
for i in range(len(str)):
if len(str)-off_new+i<=len(str)-1:
str.insert(i, str[len(str)-off_new+i])
for i in range(off_new):
str.pop()