我是靠谱客的博主 寂寞小刺猬,这篇文章主要介绍(最长重复子数组)(两个数组)(动态规划)(dp[i][j] =dp[i-1][j-1])questioncode,现在分享给大家,希望可以做个参考。

文章目录

  • 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]内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(151)

评论列表共有 0 条评论

立即
投稿
返回
顶部