题解 | #最长公共子串#

最长公共子串

http://www.nowcoder.com/practice/f33f5adc55f444baa0e0ca87ad8a6aac

alt

# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# longest common substring
# @param str1 string字符串 the string
# @param str2 string字符串 the string
# @return string字符串
#
class Solution:
    def LCS(self , str1: str, str2: str) -> str:
        # 使用滑窗的思想 
        left=0
        for i in range(len(str1)+1):
            if str1[i-left:i] in str2:
                res=str1[i-left:i]
                left+=1
        return res
```![alt](https://uploadfiles.nowcoder.com/images/20220309/974828868_1646791884518/D2B5CA33BD970F64A6301FA75AE2EB22)

![alt](https://uploadfiles.nowcoder.com/images/20220309/974828868_1646791888228/D2B5CA33BD970F64A6301FA75AE2EB22)
全部评论

相关推荐

缒梦&独舞:这家公司是这样的,去年给我实习offer了,不过也是面着玩儿的,他周六还要去做公益志愿活动
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-03 18:22
投了几百份简历,专业和方向完全对口,都已读不回。尝试改了一下学校,果然有奇效。
steelhead:这不是很正常嘛,BOSS好的是即便是你学院本可能都会和聊几句,牛客上学院本机会很少了
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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