← 返回 google 的题目列表Number of Islands
类型:online_judge
Write a function to count the number of islands in a 2D grid. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are surrounded by water. Implement num_islands(grid: List[List[str]]) -> int. For example, given '[[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 1]]', the output should be '3'.
Example
Input
[[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 1]]