package leetcode;

/**
 * https://leetcode.com/problems/max-area-of-island/
 */
public class Problem695 {
    public int maxAreaOfIsland(int[][] grid) {
        // TODO
        return 0;
    }

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

@@ -158,127 +158,425 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem695 prob = new Problem695(
+int maxRow = grid.length;%0A        int maxCol = 0;%0A        if (grid.length %3E 0) %7B%0A            maxCol = grid%5B0%5D.length;%0A        %7D%0A        boolean%5B%5D%5B%5D visited = new boolean%5BmaxRow%5D%5BmaxCol%5D;%0A        int max = 0;%0A        for (int row = 0; row %3C grid.length; row++) %7B%0A            for (int col = 0; col %3C grid%5Brow%5D.length; col++) %7B%0A                max = Math.max(max, maxAreaOfIsland(grid, visited, maxRow, maxCol, row, col)
 );%0A 
@@ -586,325 +586,463 @@
     
+ 
-System.out.println(prob.maxAreaOfIsland(new int%5B%5D%5B%5D%7B%0A            %7B0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0%7D,%0A            %7B0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0%7D,%0A            %7B0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0%7D,%0A            %7B0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0%7D,%0A            %7B0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0%7D,
+   %7D%0A        %7D%0A        return max;%0A    %7D%0A%0A    private static int maxAreaOfIsland(int%5B%5D%5B%5D grid, boolean%5B%5D%5B%5D visited, int maxRow, int maxCol,%0A                                       int row, int col) %7B%0A        if (row %3C 0 %7C%7C row %3E= maxRow %7C%7C col %3C 0 %7C%7C col %3E= maxCol) %7B%0A            return 0;%0A        %7D%0A        if (visited%5Brow%5D%5Bcol%5D) %7B%0A            return 0;%0A        %7D%0A        visited%5Brow%5D%5Bcol%5D = true;%0A        if (grid%5Brow%5D%5Bcol%5D == 0) %7B%0A            return 0;
 %0A   
@@ -1050,291 +1050,468 @@
     
+%7D%0A
     
-%7B0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0%7D,%0A            %7B0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0%7D,%0A            %7B0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0%7D%0A        %7D)); // 6%0A        System.out.println(prob.maxAreaOfIsland(new int%5B%5D%5B%5D%7B%0A            %7B0, 0, 0, 0, 0, 0, 0, 0%7D%0A        %7D)); // 0
+    int max = grid%5Brow%5D%5Bcol%5D;%0A        // up%0A        int a = maxAreaOfIsland(grid, visited, maxRow, maxCol, row - 1, col);%0A        // right%0A        int b = maxAreaOfIsland(grid, visited, maxRow, maxCol, row, col + 1);%0A        // down%0A        int c = maxAreaOfIsland(grid, visited, maxRow, maxCol, row + 1, col);%0A        // left%0A        int d = maxAreaOfIsland(grid, visited, maxRow, maxCol, row, col - 1);%0A        max += a + b + c + d;%0A        return max;
 %0A   

Solve problem 695