File tree Expand file tree Collapse file tree 1 file changed +18
-16
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +18
-16
lines changed Original file line number Diff line number Diff line change 2
2
3
3
/**
4
4
* 200. Number of Islands
5
- *
5
+ * <p>
6
6
* Given a 2d grid map of '1's (land) and '0's (water),
7
7
* count the number of islands.
8
8
* An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically.
9
9
* You may assume all four edges of the grid are all surrounded by water.
10
-
11
- Example 1:
12
- 11110
13
- 11010
14
- 11000
15
- 00000
16
- Answer: 1
17
-
18
- Example 2:
19
- 11000
20
- 11000
21
- 00100
22
- 00011
23
- Answer: 3
24
-
10
+ * <p>
11
+ * Example 1:
12
+ * 11110
13
+ * 11010
14
+ * 11000
15
+ * 00000
16
+ * Answer: 1
17
+ * <p>
18
+ * Example 2:
19
+ * 11000
20
+ * 11000
21
+ * 00100
22
+ * 00011
23
+ * Answer: 3
25
24
*/
26
25
public class _200 {
27
26
28
27
public static class Solution1 {
29
28
29
+ /**
30
+ * DFS solution, note: this modifies the input.
31
+ */
30
32
public int numIslands (char [][] grid ) {
31
33
if (grid == null || grid .length == 0 ) {
32
34
return 0 ;
You can’t perform that action at this time.
0 commit comments