← 返回 bytedance 的题目列表Count Number of Islands
类型:online_judge
You have a 2D grid map of '1's (land) and '0's (water). Your task is to count 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. Given a 2D binary grid map of m x n dimensions, compute the number of islands.
Example:
Input:
11110
11010
11000
00000
Output: 1
Input:
11000
11000
00100
00011
Output: 3
Example
Input
11110
11010
11000
00000