剑指Offer43:左旋转字符串

思路:

# -*- coding:utf-8 -*-
class Solution:
    def LeftRotateString(self, s, n):
        # write code here
        return s[n:]+s[:n]

这个方法考虑的更加全面。 

# -*- coding:utf-8 -*-
class Solution:
    def LeftRotateString(self, s, n):
        # write code here
        length=len(s)
        if length==0:
            return ""
        else:
            n=n%length
            s=s+s
            return s[n:n+length]

猜你喜欢

转载自blog.csdn.net/weixin_43160613/article/details/85599194