leetcode -- 718. 最长重复子数组
程序员文章站
2022-06-28 11:15:40
...
用动态规划
class Solution(object):
def findLength(self, A, B):
"""
:type A: List[int]
:type B: List[int]
:rtype: int
"""
LENA = len(A)
LENB = len(B)
mat = [[0]*(LENB+1) for _ in range(LENA+1)]
for i in range(1,LENA+1):
for j in range(1,LENB+1):
if A[i-1] == B[j-1]:
mat[i][j] = mat[i-1][j-1]+1
return max([max(line) for line in mat])
上一篇: Linux下RPM软件包的安装及卸载
下一篇: 718. 最长重复子数组