Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 467 Bytes

769.-rotate-string.md

File metadata and controls

22 lines (16 loc) · 467 Bytes

769. Rotate String

# Brute Force

class Solution:
    def rotateString(self, A: str, B: str) -> bool:
        if not A and not B: # Corner Case
            return True

        for _ in range(len(A)): # 遍历去找
            if A == B:
                return True
            A = self.shift(A) # 移一位
        return False

    def shift(self,str):
        return str[1:] + str[0]

     #时间复杂度O(N^2) 空间#时间复杂度O(N)