题目:请从字符串中找出至少重复一次的子字符串的最大长度
输入描述:
字符串,长度不超过1000
输出描述:
重复子串的长度,不存在输出0
示例1
输入
ababcdabcefsgg
输出
3
说明
abc为重复的最大子串,长度为3
def findMaxLen(s):
maxLen = 0
for i in range(len(s)):
for j in range(i + 1, len(s) + 1):
cp_s = s[0:i] + s[j:len(s)]
cp_s = ''.join(cp_s)
if ''.join(s[i:j]) in cp_s:
if j - i > maxLen:
maxLen = j - i
return maxLen
if __name__ == "__main__":
s = "ababcdabcefsgg"
print(findMaxLen(s))
程序运行结果:
3

abc为重复的最大子串,长度为3
网友评论