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

short=input()
long1=input()
if len(short)>len(long1):
    short,long1=long1,short
list1=[]
for i in range(len(short)):
    for j in range(i+1,len(short)):
        if short[i:j] in long1:
            list1.append(short[i:j])

list2=sorted(list1,key=len,reverse=True)
print(list2[0])

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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