大家应该是想复杂了,子串*n = 字符串
这是我的答案 ,已经通过了原地址的提交。顺便搬运2个比较好的解法
def f(words):
import re
n = len(words)
i=1
max_tuple = (words, 1)
while(i<=n/2):
pattern = r'{}'.format(words[:i])
result = re.findall(pattern, words)
if(result):
if len(result)*len(result[0]) == n and len(result)>max_tuple[1]:
max_tuple = (words[:i], len(result))
i+=1
return max_tuple
搬运1:
def find_repeat(s: str) -> tuple:
for i in range(1, len(s) + 1):
t, k = s[:i], len(s) // i
if t * k == s:
return (t, k)
搬运2:
def f(s):
m = __import__('re').match(r'^(.+?)\1*$', s)
return (m.group(1), len(s)/len(m.group(1)))