← 返回 linkedin 的题目列表Number of Islands Variation
类型:online_judge
Given a 2-D grid consisting of '1's (land) and '0's (water), compute the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. Assume all four edges of the grid are surrounded by water.
Example:
Input:
11110
11010
11000
00000
Output:
1
Input:
11000
11000
00100
00011
Output:
3
Constraints:
m == grid.length
n == grid[i].length
1 <= m, n <= 300
grid[i][j] is '0' or '1'.
Example
Input
11110
11010
11000
00000