Problem Description:
Given a non-empty string, determine whether it can be repeated multiple times by one of its substrings. The given string contains only lowercase English letters and is not more than 10000 in length.
Example 1:
Input: "Abab" output: True Explanation: can be repeated two times by sub-string "AB" composition.
Example 2:
Input: "ABA" output: False
Example 3:
Input: "ABCABCABCABC" output: True
Explanation: You can repeat the composition four times by the string "abc". (or the substring "abcabc" repeats two times.) )
Method 1:
1 classsolution (object):2 defRepeatedsubstringpattern (self, s):3 """4 : Type S:str5 : Rtype:bool6 """7n =Len (s)8 forIinchRange (1,n//2 + 1):9 ifn% i = =0:Tentemp =S[:i] Onej =I A whileJ < N andtemp = = s[j:j+i]: -J + =I - ifj = =N: the returnTrue - returnFalse
Official: Scared, scared.
1 classsolution (object):2 defRepeatedsubstringpattern (self, s):3 """4 : Type S:str5 : Rtype:bool6 """7 SS = (S * 2) [1:-1] 8 #Print SS9 returnSinchSs
2018-10-04 20:54:17
leetcode--459--repeating string