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 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 解题报告的更多相关文章
- 【LeetCode】883. Projection Area of 3D Shapes 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学计算 日期 题目地址:https://leetc ...
- [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 ...
- 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 ...
- 【LeetCode】892. Surface Area of 3D Shapes 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【Leetcode_easy】883. Projection Area of 3D Shapes
problem 883. Projection Area of 3D Shapes 参考 1. Leetcode_easy_883. Projection Area of 3D Shapes; 完
- 883. Projection Area of 3D Shapes
问题 NxN个格子中,用1x1x1的立方体堆叠,grid[i][j]表示坐标格上堆叠的立方体个数,求三视图面积. Input: [[1,2],[3,4]] Output: 17 Explanation ...
- [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 ...
- 【leetcode】883. Projection Area of 3D Shapes
题目如下: 解题思路:分别求出所有立方体的个数,各行的最大值之和,各列的最大值之和.三者相加即为答案. 代码如下: class Solution(object): def projectionArea ...
- [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 ...
随机推荐
- 【30集iCore3_ADP出厂源代码(ARM部分)讲解视频】30-6底层驱动之多路开关选择器
视频简介:该视频介绍iCore3应用开发平台中多路开关选择器的应用,多路开关选择器的硬件电路连接以及软件实现的方法. 源视频包下载地址:链接:http://pan.baidu.com/s/1geQ4W ...
- Java知多少(80)图形界面设计基础
早先程序使用最简单的输入输出方式,用户在键盘输入数据,程序将信息输出在屏幕上.现代程序要求使用图形用户界面(Graphical User Interface,GUI),界面中有菜单.按钮等,用户通过鼠 ...
- 有趣的JavaScript原生数组函数
本文由 伯乐在线 - yanhaijing 翻译.未经许可,禁止转载!英文出处:flippinawesome.欢迎加入翻译小组. 在JavaScript中,可以通过两种方式创建数组,Array构造函数 ...
- SSH远程连接Linux配置
CentOS: 开启远程连接服务:service sshd start 添加到系统启动项:chkconfig sshd on 客户端工具:windows下连接工具putty ========= ...
- [Python] 08 - Classes --> Objects
故事背景 一.阶级关系 1. Programs are composed of modules.2. Modules contain statements.3. Statements contain ...
- 国外源码精品-Android-PullToRefresh 简介与DEMO导入
转载地址:http://my.oschina.net/cuitongliang/blog/170708 (一)&&http://my.oschina.net/cuitongliang/ ...
- JS 使用html2canvas实现截图功能的问题记录和解决方案
在实现“截图”功能时,遇到几个bug,研究了一个上午,终于全部解决了: 下面给大家分享下: 1."图片资源跨域",导致无法截图. 浏览器会提示下面的错误 DOMException: ...
- hosts文件配置不生效的解决办法
分析可能的原因并给出相应的解决方案. 第一 种情况,在开启浏览器的时候修改磁盘上的hosts文件,比如说加了原先没有的一句"127.0.0.1 www.360.cn",保存host ...
- The app references non-public selector in MyApp : id
id<FBGraphUser>friend id<FBGraphUserExtraFields>user 应该使用 [user objectForKey:@"id ...
- centos6安装mysql8 shell脚本
下载mysql安装包: wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86-64.t ...