题目要求

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 zx planes.

A projection is like a shadow, that maps our 3 dimensional figure to a 2 dimensional plane.

Here, we are viewing the "shadow" when looking at the cubes from the top, the front, and the side.

Return the total area of all three projections.

题目分析及思路

题目给出了一个方阵,方阵里面的数值是柱子的高度,求三视图所有的阴影部分的面积。俯视图投影就是不为0的柱子的个数,主视图、侧视图是当前视图柱子的最高值求和。

python代码​

class Solution:

def projectionArea(self, grid):

"""

:type grid: List[List[int]]

:rtype: int

"""

top, front, side = 0, 0, 0

l = len(grid)

for i in range(l):

x, y =  0, 0

for j in range(l):

if grid[i][j] != 0:

top += 1

x = max(x, grid[i][j])

y = max(y, grid[j][i])

front += x

side += y

return top + front + side

LeetCode 883 Projection Area of 3D Shapes 解题报告的更多相关文章

  1. 【LeetCode】883. Projection Area of 3D Shapes 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学计算 日期 题目地址:https://leetc ...

  2. [LeetCode] 883. Projection Area of 3D Shapes 三维物体的投影面积

    On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes. Each ...

  3. LeetCode 892 Surface 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 ...

  4. 【LeetCode】892. Surface Area of 3D Shapes 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  5. 【Leetcode_easy】883. Projection Area of 3D Shapes

    problem 883. Projection Area of 3D Shapes 参考 1. Leetcode_easy_883. Projection Area of 3D Shapes; 完

  6. 883. Projection Area of 3D Shapes

    问题 NxN个格子中,用1x1x1的立方体堆叠,grid[i][j]表示坐标格上堆叠的立方体个数,求三视图面积. Input: [[1,2],[3,4]] Output: 17 Explanation ...

  7. [LeetCode&Python] Problem 883. Projection Area of 3D Shapes

    On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes. Each ...

  8. 【leetcode】883. Projection Area of 3D Shapes

    题目如下: 解题思路:分别求出所有立方体的个数,各行的最大值之和,各列的最大值之和.三者相加即为答案. 代码如下: class Solution(object): def projectionArea ...

  9. [LeetCode] 892. Surface 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 cu ...

随机推荐

  1. golang:吐槽multipart的设计

    最近在做邮件解析的工作,因此接触到multipart库,用了之后才发现golang的multipart有一点设计很诡异. 红线标出来的话意思是:当Content-Transfer-Encoding的值 ...

  2. FAL_CLIENT和FAL_SERVER参数详解

    FAL_CLIENT和FAL_SERVER参数详解 转载:http://openwares.net/database/fal_client_fal_server.html FAL_CLIENT和FAL ...

  3. LeetCode: Valid Parentheses 解题报告

    Valid Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', det ...

  4. 删除最少字符生成Palindrome

    看到一个哥们G家电面试题,求删除最少字符生成Palindrome.大神们都在讨论dp,我完全想不到. 放一个没优化的DFS. 乐神说是O(n3)复杂度, 有机会的话要减少使用substring,并且要 ...

  5. ( 转 )超级惊艳 10款HTML5动画特效推荐

    今天我们要来推荐10款超级惊艳的HTML5动画特效,有一些是基于CSS3和jQuery的,比较实用,特别是前几个HTML5动画,简直酷毙了,现在将它们分享给大家,也许你能用到这些HTML5动画和jQu ...

  6. [sso]搭建CAS单点服务器

    1.下载服务器端文件 Cas Client下载:http://developer.jasig.org/cas-clients/ CAS Server:cas-server-4.0.0-release. ...

  7. ubuntu: apt-get update的时候遇到“Hash Sum mismatch”错误

    http://blog.csdn.net/xjwjava/article/details/8543768 http://askubuntu.com/questions/140246/how-do-i- ...

  8. 设置gem源,解决下载慢的问题

    问题解决的最好方法方法 使用google的DNS 8.8.8.8 / 8.8.4.4 另一种解决方式 修改rubygems的source源 $ gem source -r http://rubygem ...

  9. Ubuntu下搜狗输入法只显示黑框,不显示输入的汉字选项

    1. cd ~/.config 2.删除三个文件夹: SogouPY, SogouPY.users, sogou-qimpanel 然后重启输入法

  10. 避免在构造函数中调用虚方法(Do not call overridable methods in constructors)

    CLR中说道,不要在构造函数中调用虚方法,原因是假如被实例化的类型重写了虚方法,就会执行派生类型对虚方法的实现.但在这个时候,尚未完成对继承层次结构中所有字段的初始化.所以,调用虚方法会导致不可预测的 ...