题解 | #最长公共子串#

最长公共子串

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)
全部评论

相关推荐

uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
墨西哥大灰狼:如果你的校友卤馆还在的话,他肯定会给你建议的,可是卤馆注销了@ 程序员卤馆
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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