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

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

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

a = input() b = input() ret = [] out = [] if len(a) > len(b): a, b = b, a left = right = 0 for right in range(1, len(a) + 1): while a[left:right] in b and right - 1 < len(a): ret.append(right - left) out.append(a[left:right]) right += 1 else: left += 1 pos = ret.index(max(ret)) print(out[pos])

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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