题解 | #查找两个字符串a,b中的最长公共子串#
查找两个字符串a,b中的最长公共子串
http://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506
def strings(x,y): n = len(x) m = len(y) maxlen = 1 a = '' if n >= m: for i in range(m): for j in range(i,m+1): if y[i:j] in x: curlen = j - i if maxlen < curlen : maxlen = curlen a = y[i:j] else: for i in range(n): for j in range(i,n+1): if x[i:j] in y: curlen = j - i if maxlen < curlen : maxlen = curlen a = x[i:j] print(a) x = input().strip() y = input().strip() strings(x,y)