← 返回 snapchat 的题目列表Maximum Perimeter of Island
类型:online_judge
Given a grid consisting of 0s and 1s, where 0 represents water and 1 represents land. Connected 1s form an island. Calculate the maximum perimeter of an island.
Input: A 2D integer matrix grid, where 1 represents land and 0 represents water.
Output: The maximum perimeter of an island.
Example 1:
Input: [[0, 1, 0, 0], [1, 1, 1, 0], [0, 1, 0, 0], [1, 1, 0, 0]]
Output: 8
Constraints:
1 <= grid.length, grid[0].length <= 100
grid[i][j] is 0 or 1
Example
Input
[[0, 1, 0, 0], [1, 1, 1, 0], [0, 1, 0, 0], [1, 1, 0, 0]]