您的位置:首页 > 其它

lintcode:8. 旋转字符串

2019-01-24 20:58 281 查看

lintcode:8. 旋转字符串

给定一个字符串和一个偏移量,根据偏移量旋转字符串(从左向右旋转) https://www.lintcode.com/problem/rotate-string/description

解题思路:每一次偏移实际上是取出最后一个字母,然后插在首位。

class Solution:
"""
@param str: An array of char
@param offset: An integer
@return: nothing
"""
def rotateString(self, str, offset):
# write your code here
if not str:
return
if offset > len(str):
offset = offset % len(str)
for i in range(offset):
char = str.pop()
str.insert(0,char)
return
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: