On a N * N grid, we place some 1 * 1 * 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j). Return the total surface area of the resulting shapes.   Example 1: Input: [[2]] Output: 10 Example 2: Input: […
On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes. Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j). Now we view the projection of these cubes onto the xy, yz, and…
problem 892. Surface Area of 3D Shapes 题意:感觉不清楚立方体是如何堆积的,所以也不清楚立方体之间是如何combine的.. Essentially, compute the surface area of each grid but substract the overlapping areas. All areas = surface + combined area so we have surface = * total_count - * combi…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/surface-area-of-3d-shapes/description/ 题目描述 On a N * N grid, we place some 1 * 1 * 1 cubes. Each value v = grid[i][j] represents a tower o…
On a N * N grid, we place some 1 * 1 * 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j). Return the total surface area of the resulting shapes. Example 1: Input: [[2]] Output: 10 Example 2: Input: [[1…
问题 NxN个格子中,用1x1x1的立方体堆叠,grid[i][j]表示坐标格上堆叠的立方体个数,求这个3D多边形的表面积. Input: [[1,2],[3,4]] Output: 34 思路 只要把每个柱体的表面积加起来(grid[i][j] * 4 ,4表示四个侧面,2表示上下两个面),然后减去重叠的部分即可. 重叠的部分为x方向(或y方向)上相邻柱体中较小的grid值. 时间复杂度O(n^2),空间复杂度O(1) 代码 class Solution(object): def surfac…
题目要求 On a N * N grid, we place some 1 * 1 * 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j). Return the total surface area of the resulting shapes. 题目分析及思路 给定一个N*N网格,在其上放置1*1*1的小方块,二维数组的值即为当前位置的高度,要求…
题目如下: 解题思路:对于v = grid[i][j],其表面积为s = 2 + v*4 .接下来只要在判断其相邻四个方向有没有放置立方体,有的话减去重合的面积即可. 代码如下: class Solution(object): def surfaceArea(self, grid): """ :type grid: List[List[int]] :rtype: int """ res = 0 for i in range(len(grid)):…
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4136 访问. 在 N * N 的网格上,我们放置一些 1 * 1 * 1  的立方体. 每个值 v = grid[i][j] 表示 v 个正方体叠放在单元格 (i, j) 上. 返回结果形体的总表面积. 输入:[[2]] 输出:10 示例 2: 输入:[[1,2],[3,4]] 输出:34 示例 3: 输入:[[1,0],[0,2]] 输出:16 示例 4: 输…
On a N * N grid, we place some 1 * 1 * 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j). Return the total surface area of the resulting shapes. Example 1: Input: [[2]] Output: 10 Example 2: Input: [[1…