题解 | #最长公共子串#
最长公共子串
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 re,index = -1,0 if not str1 or not str2: return -1 for i in range(len(str1)): if str1[i-index:i+1] in str2: re = str1[i-index:i+1] index += 1 return re