← 返回 snapchat 的题目列表Calculate Building's External Wall Perimeter
类型:online_judge
Given a 2D integer array grid representing a piece of land covered with buildings (1) and empty spaces (0), return the total external wall perimeter of these buildings. The external perimeter should include the walls surrounding the outside and the walls enclosing any buildings.
Input Description:
A 2D grid of integers where grid[i][j] is 0 or 1.
Output Description:
An integer representing the total perimeter of the external walls.
Example:
Input:
0 0 0
0 1 1
0 0 0
Output:
6
Here is another example:
Input:
0 0 0 0 0
0 1 1 1 0
0 1 0 1 0
0 1 1 1 0
0 0 0 0 0
Output:
12
Example
Input
0 0 0
0 1 0
0 0 0