@@ -0,0 +1,1606 @@
+package main.java.com.flang.dfs;%0A%0Apublic class NumberOfIslands %7B%0A%0A    final static int%5B%5D%5B%5D dirs = %7B%7B-1,0%7D,%7B1,0%7D,%7B0,-1%7D,%7B0,1%7D%7D;%0A%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 count = 0;%0A        final int rows = grid.length;%0A        final int cols = grid%5B0%5D.length;%0A        for (int i = 0; i %3C rows; i++) %7B%0A            for (int j = 0; j %3C cols; j++) %7B%0A                if (grid%5Bi%5D%5Bj%5D == '1') %7B%0A                    count++;%0A                    dfs(grid, i, j, rows, cols);%0A                %7D%0A            %7D%0A        %7D%0A        return count;%0A    %7D%0A%0A    private void dfs(char%5B%5D%5B%5D grid, int x, int y, int rows, int cols) %7B%0A        //base case: the current point is out of bounds or is '0'%0A        if (x %3C 0 %7C%7C x %3E= rows %7C%7C y %3C 0 %7C%7C y %3E= cols %7C%7C grid%5Bx%5D%5By%5D == '0') %7B%0A            return;%0A        %7D%0A        // recursive rule%0A        grid%5Bx%5D%5By%5D = '0';%0A        for (int%5B%5D dir : dirs) %7B%0A            int neiX = dir%5B0%5D + x;%0A            int neiY = dir%5B1%5D + y;%0A            dfs(grid, neiX, neiY, rows, cols);%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        char%5B%5D%5B%5D grids = %7B%7B'1','1','1','1','0'%7D,%0A                %7B'1','1','0','1','0'%7D,%0A                %7B'1','1','0','0','0'%7D,%0A                %7B'0','0','1','0','0'%7D%7D;%0A        System.out.println(%22row len: %22 + grids.length);%0A        System.out.println(%22col len: %22 + grids%5B0%5D.length);%0A        NumberOfIslands numberOfIslands = new NumberOfIslands();%0A        int count = numberOfIslands.numIslands(grids);%0A        System.out.println(count);%0A    %7D%0A%7D%0A

Create NumberOfIslands.java