题解 | 公共子串计算

公共子串计算

https://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b

import sys

s = input()
t = input()

max_common_string_length = 0

if len(s) >= len(t):
    for i in range(len(s)):
        for j in range(i, len(t)):
            if t[i:j+1] in s and len(t[i:j+1]) > max_common_string_length:
                max_common_string_length = len(t[i:j+1])
else:
    for i in range(len(t)):
        for j in range(i, len(s)):
            if s[i:j+1] in t and len(s[i:j+1]) > max_common_string_length:
                max_common_string_length = len(s[i:j+1])

print(max_common_string_length)

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-23 18:34
点赞 评论 收藏
分享
哥_留个offer先:跟他说,你这个最好用c#,微软就用c#Java不适合这个项目
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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