题目要求

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. Android ShareUserId 使用总结

    今天讲一下Android里面经常看到却不太留意的知识点——ShareUserId,在Android里面每个app都有一个唯一的linux user ID,则这样权限就被设置成该应用程序的文件只对该用户 ...

  2. Android应用图标微技巧,8.0系统中应用图标的适配

    现在已经进入了2018年,Android 8.0系统也逐渐开始普及起来了.三星今年推出的最新旗舰机Galaxy S9已经搭载了Android 8.0系统,紧接着小米.华为.OV等国产手机厂商即将推出的 ...

  3. Tensorflow学习笔记——安装和运行

    参考的资料: 1.官网 2.tensorflow官方文档中文版 安装的是Python 2.7; CPU support (no GPU support),版本是1.1 pip install tens ...

  4. android TV选中时高亮凸显效果

    链接: http://pan.baidu.com/s/1pLjAFQ7 密码: xb8g <ignore_js_op> 360手机助手截图0410_18_02_01.png (335.64 ...

  5. oracle表空间不足扩容的方法

    1.查询当前用户的所属表空间 select * from user_users; 2.增加表空间有两种方法: 以sysdba登陆进数据库 语法: alter tablespace 表空间名称 add ...

  6. PHP文件解密服务,微擎微赞模块解密,微擎模块解密

    支持Zend/PHP5.3, Zend/PHP5.4, Zend/PHP5.5, Zend/PHP5.6解密 支持IonCube8, IonCube9, IonCube10解密 支持魔方一代,魔方二代 ...

  7. SpringBoot------Servlet3.0的注解自定义原生Listener监听器

    前言 常用监听器: //contextListener可以监听数据库的连接,第三方组件的交互,还有静态文件加载等等 servletContextListener HttpSessionListener ...

  8. 使用 PHP_CodeSniffer 检查 代码 是否 符合 编码规范

    服务端部署:PHP_CodeSniffer HG 服务端部署篇 1.下载PHP_CodeSniffer 前往 https://github.com/squizlabs/PHP_CodeSniffer ...

  9. 精心收集的 48 个 JavaScript 代码片段,仅需 30 秒就可理解

    原文:Chalarangelo  译文:IT168 https://github.com/Chalarangelo/30-seconds-of-code#anagrams-of-string-with ...

  10. 不可思议的颜色混合模式 mix-blend-mode (转)

    开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...