代码比较简单,分为奇数偶数讨论。
如果有第19行,运行时间35ms;没有的话 39ms.
class Solution(object):
def repeatedSubstringPattern(self, str):
"""
:type str: str
:rtype: bool
"""
n=len(str)
m=n//2
if not n&1:
return str[:m]==str[m:]
else:
i=1
while i<=m:
if not n%i:
if str==str[:i]*(n//i):
return True
i+=1
return False