最长重复子数组
Sunny-117 opened this issue · comments
最长重复子数组
var findLength = function(nums1, nums2) {
const n = nums1.length;
const m = nums2.length;
const dp = new Array(n+1).fill(0).map(() => new Array(m+1).fill(0));
let res = 0;
for(let i = 1; i <= n; i++){
for(let j = 1; j <= m; j++){
if(nums1[i-1] === nums2[j - 1]){
dp[i][j] = dp[i - 1][j - 1] + 1;
}
res = Math.max(dp[i][j],res)
}
}
return res
};