← 返回 apple 的题目列表Number of Islands
类型:qbank
Given a 2D grid grid where '1' represents land and '0' represents water, count and return the number of islands.
Examples
Example 1:
Input: grid = [ ["0","1","1","1","0"], ["0","1","0","1","0"], ["1","1","0","0","0"], ["0","0","0","0","0"] ]
Output: 1
Example 2:
Input: grid = [ ["1","1","0","0","1"], ["1","1","0","0","1"], ["0","0","1","0","0"], ["0","0","0","1","1"] ]
Output: 3
Constraints
1 <= grid.length, grid[i].length <= 100
grid[i][j] is '0' or '1'.