2019-06-02 23:16:01 +08:00
|
|
|
|
#coding: utf-8
|
|
|
|
|
''' mbinary
|
|
|
|
|
#######################################################################
|
|
|
|
|
# File : max-len-of-repeated-subarray.py
|
|
|
|
|
# Author: mbinary
|
|
|
|
|
# Mail: zhuheqin1@gmail.com
|
|
|
|
|
# Blog: https://mbinary.xyz
|
|
|
|
|
# Github: https://github.com/mbinary
|
|
|
|
|
# Created Time: 2019-05-27 08:25
|
|
|
|
|
# Description:
|
|
|
|
|
给两个整数数组 A 和 B ,返回两个数组中公共的、长度最长的子数组的长度。
|
|
|
|
|
#######################################################################
|
|
|
|
|
'''
|
2020-04-15 12:28:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def findLength(A, B):
|
|
|
|
|
n, m = len(A), len(B)
|
2019-06-02 23:16:01 +08:00
|
|
|
|
dp = [[0]*(m+1) for i in range(n+1)]
|
2020-04-15 12:28:20 +08:00
|
|
|
|
for i in range(1, n+1):
|
|
|
|
|
for j in range(1, m+1):
|
|
|
|
|
if A[i-1] == B[j-1]:
|
|
|
|
|
dp[i][j] = dp[i-1][j-1]+1
|
2019-06-02 23:16:01 +08:00
|
|
|
|
return max(max(row) for row in dp)
|