@@ -0,0 +1,1225 @@
+class Solution %7B%0A    public int numIslands(char%5B%5D%5B%5D grid) %7B%0A        if (grid == null %7C%7C grid.length == 0 %7C%7C grid%5B0%5D.length == 0) %7B%0A            return 0;%0A        %7D%0A        int row = grid.length;%0A        int col = grid%5B0%5D.length;%0A        boolean%5B%5D%5B%5D visited = new boolean%5Brow%5D%5Bcol%5D;%0A        int res = 0;%0A        for (int i = 0; i %3C row; i ++) %7B%0A            for (int j = 0; j %3C col; j++) %7B%0A                if (grid%5Bi%5D%5Bj%5D == '1' && !visited%5Bi%5D%5Bj%5D) %7B%0A                    res++;%0A                    dfs(grid, i, j, visited);%0A                %7D%0A            %7D%0A        %7D%0A        return res;%0A    %7D%0A%0A    private void dfs(char%5B%5D%5B%5D grid, int x, int y, boolean%5B%5D%5B%5D visited) %7B%0A        visited%5Bx%5D%5By%5D = true;%0A        int%5B%5D%5B%5D dirs = %7B%7B0, -1%7D, %7B0, 1%7D, %7B1, 0%7D, %7B-1, 0%7D%7D;%0A        for (int i = 0; i %3C 4; i++) %7B%0A            int newx = x + dirs%5Bi%5D%5B0%5D;%0A            int newy = y + dirs%5Bi%5D%5B1%5D;%0A            if (inArea(grid, newx, newy) && !visited%5Bnewx%5D%5Bnewy%5D && grid%5Bnewx%5D%5Bnewy%5D == '1') %7B%0A                dfs(grid, newx, newy, visited);%0A            %7D%0A        %7D%0A    %7D%0A%0A    private boolean inArea(char%5B%5D%5B%5D grid, int x, int y) %7B%0A        int row = grid.length;%0A        int col = grid%5B0%5D.length;%0A        return 0 %3C= x && x %3C row && 0 %3C= y && y %3C col;%0A    %7D%0A%7D

200. Number of Islands