题解 | #查找两个字符串a,b中的最长公共子串#
查找两个字符串a,b中的最长公共子串
https://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506
a = input().strip() # 短abcdefghijklmnop
b = input().strip() # 长abcsafjklmnopqrstuvw
ls = []
res = []
## jklmnop
if len(a) > len(b):
a,b = b,a # 保证a是较短的子串
p = 0 #p表示最大长度,遇强则强,最后的p肯定是最长的
for i in range(len(a)):
for j in range(1,len(a)+1):
if a[i:j] in b:
ls.append(j-i+1)
if j-i+1 > p:
p = j-i+1
res.append(a[i:j])
print(res[-1])
