leetcode892. Surface Area of 3D Shapes
You are given an?n x n
?grid
?where you have placed some?1 x 1 x 1
?cubes. Each value?v = grid[i][j]
?represents a tower of?v
?cubes placed on top of cell?(i, j)
.
After placing these cubes, you have decided to glue any directly adjacent cubes to each other, forming several irregular 3D shapes.
Return?the total surface area of the resulting shapes.
Note:?The bottom face of each shape counts toward its surface area.
?
Example 1:
Input: grid = [[1,2],[3,4]]Output: 34
Example 2:
Input: grid = [[1,1,1],[1,0,1],[1,1,1]]Output: 32
Example 3:

Input: grid = [[2,2,2],[2,1,2],[2,2,2]]Output: 46
?
Constraints:
n == grid.length == grid[i].length
1 <= n <= 50
0 <= grid[i][j] <= 50
Accepted
27,339
Submissions
44,530
橫排重復(fù)(i),縱排重復(fù)(j),上下重復(fù)(i,j)>1時候的面算出來,然后正方體的總數(shù)*6-重復(fù)的面就能得出;
Success
Details?
Runtime:?3 ms, faster than?83.66%?of?Java?online submissions for?Surface Area of 3D Shapes.
Memory Usage:?45 MB, less than?7.78%?of?Java?online submissions for?Surface Area of 3D Shapes.