欢迎光临散文网 会员登陆 & 注册

leetcode892. Surface Area of 3D Shapes

2022-02-14 15:29 作者:您是打尖儿还是住店呢  | 我要投稿

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



横排重复(i),纵排重复(j),上下重复(i,j)>1时候的面算出来,然后正方体的总数*6-重复的面就能得出;

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.


leetcode892. Surface Area of 3D Shapes的评论 (共 条)

分享到微博请遵守国家法律