1、问题描述
给定一个字符串(以字符数组的形式)和一个偏移量,根据偏移量原地从左向右旋转字符串
2、问题示例
输入str=“abcdefg”,offset=3,输出"efgabcd"
输入str=“abcdefg”,offset=1,输出"gabcdef"
3、代码实现
class Solution:
def rotateString(self, s, offset):
if len(s) > 0:
offset = offset % len(s)
temp = (s + s)[len(s) - offset : 2 * len(s) - offset]
for i in range(len(temp)):
s[i] = temp[i]
if __name__ == '__main__':
s = ['a','b','c','d','e','f','g']
offset = 3
solution = Solution()
solution.rotateString(s,offset)
print(s)