Repeated Substring Pattern
Input:
"abab"
Output:
True
Explanation:
It's the substring "ab" twice.Input:
"aba"
Output:
False题目大意:
Last updated
Input:
"abab"
Output:
True
Explanation:
It's the substring "ab" twice.Input:
"aba"
Output:
FalseLast updated
Input:
"abcabcabcabc"
Output:
True
Explanation:
It's the substring "abc" four times. (And the substring "abcabc" twice.)class Solution(object):
def repeatedSubstringPattern(self, s):
"""
:type s: str
:rtype: bool
"""
for i in xrange(1, len(s)/2+1):
if len(s)%i == 0:
l = len(s)/i
sub = s[:i]
if sub*l == s:
return True
return False