文章目录
- question
- code
question

code
class Solution {
public int findLength(int[] A, int[] B) {
if (A.length == 0 || B.length == 0) {
return 0;
}
int[][] dp = new int[A.length+1][B.length+1];
int result = 0;
for (int i = 1; i <= A.length; i++) {
for (int j = 1; j <= B.length; j++) {
if (A[i-1] == B[j-1]) {
dp[i][j] = dp[i-1][j-1]+1;
result = Math.max(result, dp[i][j]);
}
}
}
return result;
}
}
最后
以上就是寂寞小刺猬最近收集整理的关于(最长重复子数组)(两个数组)(动态规划)(dp[i][j] =dp[i-1][j-1])questioncode的全部内容,更多相关(最长重复子数组)(两个数组)(动态规划)(dp[i][j]内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复