MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / numIslands

Method numIslands

Java/NumberOfIslands.java:29–54  ·  view source on GitHub ↗

@param grid @return

(char[][] grid)

Source from the content-addressed store, hash-verified

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 *

Callers

nothing calls this directly

Calls 1

_numIslandsMethod · 0.95

Tested by

no test coverage detected