题解 | #最长公共子串#
最长公共子串
https://www.nowcoder.com/practice/f33f5adc55f444baa0e0ca87ad8a6aac
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 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:
# write code here
res=''
ln=len(str1)
left=0
for i in range(ln):
if str1[left:i+1] in str2:
res=str1[left:i+1]
else:
left +=1
return res
