https://github.com/imhuay/Algorithm_for_Interview-Chinese/blob/master/Algorithm_for_Interview/_笔试/拼多多180722/2.字符串构造.py
""" | |
字符串构造 | |
问题描述: | |
一个长串由一个字串循环构成,即 s[i]=t[i%n],比如 "abcabc" 由 "abc" 构成 | |
注意:"abcabcab" 也是由 "abc" 构成的,答题时没注意这个又只过了一部分 | |
*建议使用 Python 解决字符串相关问题,下面也只贴 Python 代码 | |
""" |
思路:
1、从收字符开始,求出最长重复出现的字串即可;
s=input()
res,i,limit=‘‘,1,len(s)//2
while True:
longestRepeat=s[0:i]
if longestRepeat in s:
res=longestRepeat
i+=1
if i==limit:
break
else:
break
print(res)
原文:https://www.cnblogs.com/yuanjiangw/p/10533145.html