题解 | #查找两个字符串a,b中的最长公共子串#
查找两个字符串a,b中的最长公共子串
https://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506
while 1:
try:
s_short = input()
str_long = input()
if len(s_short) > len(str_long):
s_short, str_long = str_long, s_short
note = [[], []]
for i in range(len(s_short)):
for j in range(len(s_short), i+1, -1):
if s_short[i:j] in str_long:
note[0].append(s_short[i:j])
note[1].append(j - i)
print(note[0][note[1].index(max(note[1]))])
except:
break
联想公司福利 1523人发布