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

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

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

第一遍没看清“输出在较短串中最先出现的那个”,淦!

while True:
    try:
        s1 = input()
        s2 = input()
        res = []
        if len(s1) <= len(s2):
            for i in range(len(s1)):
                for j in range(i+1,len(s1)+1):
                        if s1[i:j] in s2:
                            res.append(s1[i:j])
        else:
            for i in range(len(s2)):
                for j in range(i+1,len(s2)+1):
                        if s2[i:j] in s1:
                            res.append(s2[i:j])
        opt = []
        for i in res:
            if len(i) > len(opt):
                opt = i
        print(opt)
    except:
        break
全部评论

相关推荐

这不纯纯作弊了吗😢😢😢
编程界菜鸡:信这个的这辈子有了,这智商你靠啥都没用
点赞 评论 收藏
分享
05-14 20:34
门头沟学院 Java
窝补药贝八股:管他们,乱说,反正又不去,直接说680
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-30 18:19
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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