Skip to content

Latest commit

 

History

History
18 lines (16 loc) · 443 Bytes

459.md

File metadata and controls

18 lines (16 loc) · 443 Bytes

459. Repeated Substring Pattern

Solution 1 (time O(n^2), space O(1))

class Solution(object):
    def repeatedSubstringPattern(self, s):
        """
        :type s: str
        :rtype: bool
        """
        n = len(s)
        for i in range(1,  n // 2 + 1):
            if n % i == 0:
                if all(s[j] == s[j - i] for j in range(i, n)):
                    return True
        return False