作者: 负雪明烛 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…
题目如下: 解题思路:对于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)):…
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/projection-area-of-3d-shapes/description/ 题目描述 On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, an…
题目如下: 解题思路:分别求出所有立方体的个数,各行的最大值之和,各列的最大值之和.三者相加即为答案. 代码如下: class Solution(object): def projectionArea(self, grid): """ :type grid: List[List[int]] :rtype: int """ front = [0] * len(grid) side = [0] * len(grid) top = 0 for i in…
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…
problem 883. Projection Area of 3D Shapes 参考 1. Leetcode_easy_883. Projection Area of 3D Shapes; 完…
题目要求 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的小方块,二维数组的值即为当前位置的高度,要求…
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: […