题解 | 查找两个字符串a,b中的最长公共子串
查找两个字符串a,b中的最长公共子串
https://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506
import sys s = sys.stdin.readline().strip() t = sys.stdin.readline().strip() if len(s) > len(t): s,t = t,s i,res = 0,'' for j in range(len(s)): while s[i:j+1] not in t and i <= j: i += 1 if s[i:j+1] in t and j-i+1 > len(res): res = s[i:j+1] print(res)
滑动窗口最优解