Simple Python Solution


  • 0
    S
    class Solution(object):
        def repeatedSubstringPattern(self, str):
            """
            :type str: str
            :rtype: bool
            """
            s = str
            N = len(s)
            j = 1
            while True:
                if j > N/2:
                    break
                ss = s[0:j]
                k = j
                while True:
                    if not s[k:k+j] == ss:
                        break
                    if k+j == len(s):
                        return True
                    k += j
                j += 1
            return False
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.