← 返回 amazon 的题目列表Remove Border Islands
类型:online_judge
Given a 2D grid of '1's and '0's representing land and water, write code to remove all islands that are connected to the borders of the grid and return the number of remaining islands. Islands are connected by neighboring horizontally or vertically adjacent land. The input grid size will not exceed 100. Input/Output Format: Input is a 2D character grid, output is an integer representing the number of remaining islands.
Example:
Input:
[
['1', '1', '0', '0', '0'],
['0', '1', '0', '0', '1'],
['1', '0', '0', '1', '1'],
['0', '0', '0', '0', '0'],
['0', '0', '1', '1', '1']
]
Output:
2
Example
Input
5 5
11000
01001
10011
00000
00111