package leetcode;

/**
 * https://leetcode.com/problems/image-overlap/
 */
public class Problem835 {
    public int largestOverlap(int[][] A, int[][] B) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem835 prob = new Problem835();
        System.out.println(prob.largestOverlap(new int[][]{
            {1, 1, 0},
            {0, 1, 0},
            {0, 1, 0}
        }, new int[][]{
            {0, 0, 0},
            {0, 1, 1},
            {0, 0, 1}
        })); // 3
    }
}

@@ -12,16 +12,68 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 /**%0A * h
@@ -212,367 +212,2232 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem835 prob = new Problem835();%0A        System.out.println(prob.largestOverlap(new int%5B%5D%5B%5D%7B%0A            %7B1, 1, 0%7D,%0A            %7B0, 1, 0%7D,%0A            %7B0, 1, 0%7D%0A        %7D, new int%5B%5D%5B%5D%7B%0A            %7B0, 0, 0%7D,%0A            %7B0, 1, 1%7D,%0A            %7B0, 0, 1%7D%0A        %7D)); // 3
+int maxRow = A.length;%0A        int maxCol = (A.length %3E 0) ? A%5B0%5D.length : 0;%0A        List%3Cint%5B%5D%3E list = new ArrayList%3C%3E();%0A        for (int row = 0; row %3C maxRow; row++) %7B%0A            for (int col = 0; col %3C maxCol; col++) %7B%0A                if (A%5Brow%5D%5Bcol%5D == 1) %7B%0A                    list.add(new int%5B%5D%7Brow, col%7D);%0A                %7D%0A            %7D%0A        %7D%0A        int max = 0;%0A        for (int down = 0; down %3C maxRow; down++) %7B%0A            for (int right = 0; right %3C maxCol; right++) %7B%0A                int count = 0;%0A                for (int%5B%5D cell : list) %7B%0A                    int row = cell%5B0%5D + down;%0A                    int col = cell%5B1%5D + right;%0A                    if (row %3C maxRow && col %3C maxCol && B%5Brow%5D%5Bcol%5D == 1) %7B%0A                        count++;%0A                    %7D%0A                %7D%0A                max = Math.max(max, count);%0A            %7D%0A            for (int left = maxCol; left %3E= 0; left--) %7B%0A                int count = 0;%0A                for (int%5B%5D cell : list) %7B%0A                    int row = cell%5B0%5D + down;%0A                    int col = cell%5B1%5D - left;%0A                    if (row %3C maxRow && col %3E= 0 && B%5Brow%5D%5Bcol%5D == 1) %7B%0A                        count++;%0A                    %7D%0A                %7D%0A                max = Math.max(max, count);%0A            %7D%0A        %7D%0A        for (int up = maxRow - 1; up %3E= 0; up--) %7B%0A            for (int right = 0; right %3C maxCol; right++) %7B%0A                int count = 0;%0A                for (int%5B%5D cell : list) %7B%0A                    int row = cell%5B0%5D - up;%0A                    int col = cell%5B1%5D + right;%0A                    if (row %3E= 0 && col %3C maxCol && B%5Brow%5D%5Bcol%5D == 1) %7B%0A                        count++;%0A                    %7D%0A                %7D%0A                max = Math.max(max, count);%0A            %7D%0A            for (int left = maxCol; left %3E= 0; left--) %7B%0A                int count = 0;%0A                for (int%5B%5D cell : list) %7B%0A                    int row = cell%5B0%5D - up;%0A                    int col = cell%5B1%5D - left;%0A                    if (row %3E= 0 && col %3E= 0 && B%5Brow%5D%5Bcol%5D == 1) %7B%0A                        count++;%0A                    %7D%0A                %7D%0A                max = Math.max(max, count);%0A            %7D%0A        %7D%0A        return max;
 %0A   

Solve problem 835