Example 1
Input
grid = [["1","1","0"],["1","0","0"],["0","0","1"]]
Output
2
Loading CodeSprint...
/problems/number-of-islands
A grid uses "1" for land and "0" for water. Count the separate land regions connected vertically or horizontally.
Implement this function and return the result. CodeSprint supplies each test case automatically.
numIslands(grid) → numberInput
grid = [["1","1","0"],["1","0","0"],["0","0","1"]]
Output
2
Input
grid = [["0","0"],["0","0"]]
Output
0
Constraints
1 <= grid rows, columns <= 300 Every cell is either "0" or "1".