题解 | #查找两个字符串a,b中的最长公共子串#
查找两个字符串a,b中的最长公共子串
https://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506
a = input() b = input() l = [] maxl = '' if len(a) > len(b): a, b = b, a for i in range(len(a)): for j in range(len(a), i, -1): if a[i:j] in b and len(a[i:j]) > len(maxl): maxl = a[i:j] print(maxl)
按顺序从长字串逐渐缩小范围