leetcode 796. Rotate String 旋转字符串 python 字符串的切片操作

class Solution:
    def rotateString(self, A, B):
        """
        :type A: str
        :type B: str
        :rtype: bool
        """
        if A != B:      # 处理空字符串的特殊情况
            for _ in range(len(A)):
                if A == B : return True
                A = A[1:] + A[0]
            return False
        return True

猜你喜欢

转载自blog.csdn.net/huhehaotechangsha/article/details/80902735