package leetcode;

/**
 * https://leetcode.com/problems/maximum-length-of-repeated-subarray/
 */
public class Problem718 {
    public int findLength(int[] A, int[] B) {
        int max = 0;
        int[][] memo = new int[A.length + 1][B.length + 1];
        for (int i = A.length - 1; i >= 0; i--) {
            for (int j = B.length - 1; j >= 0; j--) {
                if (A[i] == B[j]) {
                    memo[i][j] = memo[i + 1][j + 1] + 1;
                }
                max = Math.max(max, memo[i][j]);
            }
        }
        return max;
    }
}

@@ -556,11 +556,884 @@
 x;%0A    %7D
+%0A%0A//    public int findLength(int%5B%5D A, int%5B%5D B) %7B%0A//        int max = 0;%0A//        Integer%5B%5D%5B%5D memo = new Integer%5BA.length + 1%5D%5BB.length + 1%5D;%0A//        for (int i = 0; i %3C A.length; i++) %7B%0A//            for (int j = 0; j %3C B.length; j++) %7B%0A//                max = Math.max(max, findLength(A, B, i, j, memo));%0A//            %7D%0A//        %7D%0A//        return max;%0A//    %7D%0A//%0A//    private static int findLength(int%5B%5D a, int%5B%5D b, int i, int j, Integer%5B%5D%5B%5D memo) %7B%0A//        if (i == a.length) %7B%0A//            return 0;%0A//        %7D%0A//        if (j == b.length) %7B%0A//            return 0;%0A//        %7D%0A//        int max = 0;%0A//        if (memo%5Bi%5D%5Bj%5D != null) %7B%0A//            return memo%5Bi%5D%5Bj%5D;%0A//        %7D%0A//        if (a%5Bi%5D == b%5Bj%5D) %7B%0A//            max = Math.max(max, findLength(a, b, i + 1, j + 1, memo) + 1);%0A//        %7D%0A//        memo%5Bi%5D%5Bj%5D = max;%0A//        return max;%0A//    %7D
 %0A%7D%0A

Update problem 718