1. 程式人生 > >LintCode 8. 旋轉字串

LintCode 8. 旋轉字串

8. 旋轉字串 

給定一個字串和一個偏移量,根據偏移量旋轉字串(從左向右旋轉)

樣例

對於字串 "abcdefg".

offset=0 => "abcdefg"
offset=1 => "gabcdef"
offset=2 => "fgabcde"
offset=3 => "efgabcd"
class Solution:
    """
    @param str: An array of char
    @param offset: An integer
    @return: nothing
    """
    def rotateString(self, str, offset):
        # write your code hereif not offset: return
        if len(str) == 0 or offset == 0:
            return str
        for i in range(offset%len(str)):
            str.insert(0,str.pop())