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]