题解 | 查找两个字符串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)

滑动窗口最优解

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务