@param grid @return
(char[][] grid)
| 27 | * @return |
| 28 | */ |
| 29 | public int numIslands(char[][] grid) { |
| 30 | |
| 31 | if (grid == null || grid.length == 0) { |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | r = grid.length; |
| 37 | c = grid[0].length; |
| 38 | islands = 0; |
| 39 | visited = new boolean[r][c]; |
| 40 | |
| 41 | for (int i = 0; i < r; i++) { |
| 42 | |
| 43 | for (int j = 0; j < c; j++) { |
| 44 | |
| 45 | if (grid[i][j] == '1' && !visited[i][j]) { |
| 46 | |
| 47 | _numIslands(grid, i, j); |
| 48 | islands++; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return islands; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * |
nothing calls this directly
no test coverage detected