题解 | #查找两个字符串a,b中的最长公共子串#
查找两个字符串a,b中的最长公共子串
https://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506
s1 = input().strip()
s2 = input().strip()
if len(s1) > len(s2):
s1, s2 = s2, s1
n = len(s1)
m = len(s2)
res = ''
for i in range(n):
for j in range(i+1,n):
if s1[i:j+1] in s2 and j+1-i > len(res):
res = s1[i:j+1]
print(res)
查看2道真题和解析
阿里云成长空间 745人发布