题解 | #最长公共子串#
最长公共子串
https://www.nowcoder.com/practice/f33f5adc55f444baa0e0ca87ad8a6aac
class Solution: def LCS(self , str1: str, str2: str) -> str: #dp[i][j]表示到str1第i个个到str2第j个为止的公共子串长度 maxl = 0 pos = 0 for i in range(len(str1)): while i+maxl+1<=len(str1): if str1[i:i+maxl+1] in str2: maxl = maxl+1 pos = i else: break return str1[pos:pos+maxl]