medium
Number of Islands
A grid contains 1 for land and 0 for water. An island is a maximal group of land cells connected horizontally or vertically. Count the islands.
Constraints
- 1 ≤ m, n ≤ 300
- grid[i][j] ∈ {0, 1}
Examples
in: grid = [["1","1","0","0"],["1","0","0","1"],["0","0","1","1"]]
out: 3
Code it yourself
Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?
Choose an approach to check your pattern recognition, or reveal the discussion when you need help.