[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 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.
Example 1:
Input: [[2]]
Output: 5
Example 2:
Input: [[1,2],[3,4]]
Output: 17
Explanation:
Here are the three projections ("shadows") of the shape made with each axis-aligned plane.
![]()
Example 3:
Input: [[1,0],[0,2]]
Output: 8
Example 4:
Input: [[1,1,1],[1,0,1],[1,1,1]]
Output: 14
Example 5:
Input: [[2,2,2],[2,1,2],[2,2,2]]
Output: 21
Note:
1 <= grid.length = grid[0].length <= 50
0 <= grid[i][j] <= 50
This problem is just like the problem 807. We just need to find the max element in each row and column and find the number of nonzero elements. Then the sum of them is the answer.
class Solution:
def projectionArea(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
""" rAf=sum([max(r) for r in grid])+sum([max(c) for c in zip(*grid)]) m=len(grid)
n=len(grid[0]) num=0 for r in grid:
num+=r.count(0) return (m*n-num)+rAf
[LeetCode&Python] Problem 883. Projection Area of 3D Shapes的更多相关文章
- [LeetCode&Python] Problem 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 ...
- 【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】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 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. ...
- 【leetcode】883. Projection Area of 3D Shapes
题目如下: 解题思路:分别求出所有立方体的个数,各行的最大值之和,各列的最大值之和.三者相加即为答案. 代码如下: class Solution(object): def projectionArea ...
- [Swift]LeetCode883. 三维形体投影面积 | 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 ...
- Leetcode883.Projection Area of 3D Shapes三维形体投影面积
在 N * N 的网格中,我们放置了一些与 x,y,z 三轴对齐的 1 * 1 * 1 立方体. 每个值 v = grid[i][j] 表示 v 个正方体叠放在单元格 (i, j) 上. 现在,我们查 ...
随机推荐
- QString 编码转换
参考网址:http://blog.csdn.net/lfw19891101/article/details/6641785 (网页保存于:百度云CodeSkill33 --> 全部文件 > ...
- 枚举1--求小于n的最大素数
枚举1--求小于n的最大素数 总结: 素数是不能被比它小的素数整除. /* 枚举就是基于已有知识镜像答案猜测的一种问题求解策略 问题:求小于n的最大素数 分析: 找不到一个数学公式,使得根据N就可以计 ...
- vs.net应用程序图标以及制作安装程序快捷方式图标设置
我们通常在开发软件完毕后需要打包制作安装程序,这个时侯一般都会需要设置应用程序的图标,使用默认的图标一般都比较难看,那么我们应该怎样设置自定义的图标呢? 我现在要讲的图标设置有两种情况, ...
- Confluence 6 使用 LDAP 授权连接一个内部目录 - Schema 设置
基本 DN(Base DN) 根专有名称(DN),这个名称在你对目录服务器上进行查询的时候使用.例如: o=example,c=com cn=users,dc=ad,dc=example,dc=com ...
- Redis基础知识点面试手册
Redis基础知识点面试手册 基础 概述 数据类型 STRING LIST SET HASH ZSET(SORTEDSET) 数据结构 字典 跳跃表 使用场景 会话缓存 缓存 计数器 查找表 消息队列 ...
- Generate PDF in Sourcing through concurrent request,在EBS java并发中调用指定am的方法
package oracle.apps.pon.printing.cp; import java.io.InputStream; import java.io.FileOutputStream; im ...
- 62. 63. Unique Paths 64. Minimum Path Sum
1. A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- OC description和sel
一.description方法 Description方法包括类方法和对象方法.(NSObject类所包含) (一)基本知识 -description(对象方法) 使用NSLog和@%输出某个对象时, ...
- git 系统找不到 指定的路径
git 系统找不到 指定的路径 %HOMEDRIVE%%HOMEPATH% Home 问题解决
- 封装一个简单的原生js焦点轮播图插件
轮播图实现的效果为,鼠标移入左右箭头会出现,可以点击切换图片,下面的小圆点会跟随,可以循环播放(为了方便理解,没有补2张图做无缝轮播).本篇文章的主要目的是分享封装插件的思路. 轮播图我一开始是写成非 ...