leetcode 127 最长公共子串 python
给定两个字符串str1和str2,输出两个字符串的最长公共子串 题目保证str1和str2的最长公共子串存在且唯一。
class Solution:
def LCS(self , str1 , str2 ):
# write code here
s1,s2='',''
for i in str1:
s1=s1+i
if s1 in str2:
if len(s1)>len(s2):
s2=s1
else:
s1=s1[1:]
return s2