题解 | #MP3光标位置#
查找两个字符串a,b中的最长公共子串
http://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506
def same_substr(s1, s2):
if len(s1) > len(s2):
s1, s2 = s2, s1
subs = []
for i in range(len(s1)-1):
tmp = s1[i]
if tmp not in s2:
continue
if not subs:
subs.append(s1[i])
for j in range(i+1, len(s1)):
tmp += s1[j]
if tmp in s2:
if len(tmp) > len(max(subs, key=len)):
subs.append(tmp)
else:
continue
else:
break
return max(subs, key=len)
while 1:
try:
s1 = input()
s2 = input()
print(same_substr(s1, s2))
except:
break