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)