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

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

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

def myfunc(x):
    for j in range(len(a)-x+1):
        if a[j:j+x] in b:
            return(a[j:j+x])
    return None

while True:
    try:
        a = input() #short
        b = input() #long
        if len(a) > len(b):
            a, b = b, a
        for i in range(len(a),0,-1):
            result = myfunc(i)
            if result != None:
                break
        print(result)
    except:
        break
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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