leetcode -. 459 repeated substring

Simple question, the effect is not good enough

class Solution:
    def repeatedSubstringPattern(self, s: str) -> bool:
        a=''
        for i in range(len(s)):
            if s[i] not in a:
                a+=s[i]
            else:
                if a == s[i:i+len(a)]:
                    if s==a*(len(s)//len(a)):
                        return True
                    else:
                        a+=s[i]
                else:
                    a+=s[i]
        return False
When execution: 184 ms, beat the 19.12% of users in all python3 submission
Memory consumption: 13.8 MB, beat the 5.08% of users in all python3 submission
 
                                                                                   ——2019.10.18

Guess you like

Origin www.cnblogs.com/taoyuxin/p/11698324.html