← 返回 amazon 的题目列表Number of Islands
类型:online_judge
Given an m x n 2D grid grid of characters '1' (land) and '0' (water), return the number of islands.
An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically (no diagonal connections).
Input format (stdin)
First line: two integers m n for the number of rows and columns.
Next m lines: each line is a string of length n containing only 0 and 1.
Output format (stdout)
Print one integer: the number of islands.
Constraints
1 <= m, n <= 300
Example
Input:
4 5
11000
11000
00100
00011
Output:
3
Example
Input
1 1
0
Output
0