本文共 400 字,大约阅读时间需要 1 分钟。
class Solution: def findLength(self, A: List[int], B: List[int]) -> int: dp = [[0] * (len(B)+1) for _ in range(len(A)+1)] for i in range(1, len(A)+1): for j in range(1, len(B)+1): if A[i-1] == B[j-1]: dp[i][j] = dp[i-1][j-1]+1 else: dp[i][j] = 0 return max(max(row) for row in dp)
转载地址:http://bdsl.baihongyu.com/