题解 | #查找两个字符串a,b中的最长公共子串#
查找两个字符串a,b中的最长公共子串
https://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506
str1 = input().strip() str2 = input().strip() import sys if len(str1) > len(str2): tamp = str1 str1 = str2 str2 = tamp if str1 in str2: print(str1) else: for i in range(len(str1)-1,1,-1): for j in range(len(str1)-i+1): if str1[j:j+i] in str2: print(str1[j:j+i]) sys.exit()