题解 | #查找两个字符串a,b中的最长公共子串#

查找两个字符串a,b中的最长公共子串

http://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506

while True:
    try:
        l1,l2 = input(),input()
        if len(l1) > len(l2):
            l1,l2 = l2,l1
        s = ''
        for i in range(len(l1)):
            for j in range(i,len(l1)):
                if l1[i:j+1] in l2 and j-i+1>len(s):
                    s = l1[i:j+1]
                else:
                    continue
        print(s)
    except:
        break
全部评论

相关推荐

点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-19 14:56
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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