Simple intuitive python solution using startswith function for subsequent substrings

  • 0
        def repeatedSubstringPattern(self, str):
            :type str: str
            :rtype: bool
            for i in range(1,len(str)) :
                a = str[0:i]; j = i
                while j < len(str) :
                    if not str.startswith(a, j) : break
                    j += i
                if j == len(str) : return True
            return False

Log in to reply

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