← 返回 microsoft 的题目列表Number of Islands
类型:online_judge
Problem: Number of Islands
Given an m x n 2D grid of characters '1' land and '0' water, return the number of islands.
An island is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are surrounded by water.
Input Format
The first line contains two integers m n.
The next m lines each contain n characters, either 0 or 1. Characters may be written with or without spaces.
Output Format
Print one integer: the number of islands.
Constraints
1 <= m, n <= 300
grid[i][j] is '0' or '1'
Example
Input:
4 5
11110
11010
11000
00000
Output:
1
Example
Input
4 5
11110
11010
11000
00000
Output
1