题解 | #公共子串计算#
公共子串计算
https://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b
s = [] s.append(input()) s.append(input()) if len(s[0]) > len(s[1]): s1 = s[1] s2 = s[0] else: s1 = s[0] s2 = s[1] dp = [0 for _ in range(len(s1))] for i in range(len(s1)): for j in range(len(s2)): if s1[i] == s2[j]: l = 0 x, y = i, j while x >= 0 and y >= 0 and s1[x] == s2[y]: l += 1 x -= 1 y -= 1 dp[i] = max(dp[i], l) print(max(dp))