package leetcode;

/**
 * https://leetcode.com/problems/island-perimeter/
 */
public class Problem463 {
    public int islandPerimeter(int[][] grid) {
        // TODO
        return 0;
    }

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

@@ -156,15 +156,371 @@
     
-// TODO
+int maxRow = grid.length;%0A        int maxCol = grid%5B0%5D.length;%0A        boolean%5B%5D%5B%5D visited = new boolean%5BmaxRow%5D%5BmaxCol%5D;%0A        for (int i = 0; i %3C maxRow; i++) %7B%0A            for (int j = 0; j %3C maxCol; j++) %7B%0A                if (grid%5Bi%5D%5Bj%5D == 1) %7B%0A                    return visit(grid, visited, maxRow, maxCol, i, j);%0A                %7D%0A            %7D%0A        %7D
 %0A   
@@ -550,21 +550,22 @@
    p
-ublic
+rivate
  static 
 void
@@ -564,249 +564,782 @@
 tic 
-void main(String%5B%5D args) %7B%0A        Problem463 prob = new Problem463();%0A        System.out.println(prob.islandPerimeter(new int%5B%5D%5B%5D%7B%0A            %7B0,1,0,0%7D,%0A            %7B1,1,1,0%7D,%0A            %7B0,1,0,0%7D,%0A            %7B1,1,0,0%7D%0A        %7D)); // 16
+int visit(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 1;%0A        %7D%0A        if (visited%5Brow%5D%5Bcol%5D) %7B%0A            return 0;%0A        %7D%0A        if (grid%5Brow%5D%5Bcol%5D == 0) %7B%0A            return 1;%0A        %7D%0A        visited%5Brow%5D%5Bcol%5D = true;%0A        int a = 0;%0A        // top%0A        int b = visit(grid, visited, maxRow, maxCol, row - 1, col);%0A        // right%0A        int c = visit(grid, visited, maxRow, maxCol, row, col + 1);%0A        // bottom%0A        int d = visit(grid, visited, maxRow, maxCol, row + 1, col);%0A        // left%0A        int e = visit(grid, visited, maxRow, maxCol, row, col - 1);%0A        return a + b + c + d + e;
 %0A   

Solve problem 463