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 ...
随机推荐
- 模仿jQuery的ajax的封装
/* * 我们使用了ajax 的xmlHttpRequest 跟服务器进行交互. * * 交互了有四个基本步骤 * 1:创建对象 * 2:建立连接 * 3:发送请求 * 4:接收数据 * * 这些操作 ...
- anaconda的kernel对jupyter可见
在anaconda的kernel下,安装nb_conda_kernels conda install nb_conda_kernels 参考这篇博客
- 【WPF】ListBox GridViewColumn Header 文字换行、文字多行显示
ListBox GridViewColumn Header 文字换行.文字多行显示,在Header中需要换行的地方写 <GridViewColumn Header="空间另存 为总量& ...
- 创建shell脚本
1.写一个脚本 a) 用touch命令创建一个文件:touch my_script b) 用vim编辑器打开my_script文件:vi my_script c) 用vim编辑器编辑my_script ...
- laravel5.4 表单提交
1.路由配置: Route::post('/posts', '\App\Http\Controllers\PostController@store'); 2.防止csrf攻击 @section('co ...
- swoole 定时器
timer.php <?php //创建websocket服务器对象,监听0.0.0.0:9502端口 $ws = ); swoole_timer_tick(, function ($timer ...
- Unity3D中Layers和LayerMask解析
Unity中是用int32来表示32个Layer层.int32表示二进制一共有32位(0—31).在Unity中可编辑的Layer如下图所示: 在Unity中每个GameObject都有Layer ...
- [Laravel] 02 - Route and MVC
前言 一.良心资料 英文 Laravel 框架:https://laravel.com/ 教程:https://laracasts.com/series/ laravel-from-scratch-2 ...
- spray 处理 response 的通用函数
def handleActorResponse: PartialFunction[Try[Any], (StatusCode, ResponseResult)] = { case Failure(ex ...
- Zoomit的用法总结
今天才发现Zoomit,相见恨晚.总结一下zoomit的使用方法,备用. Zoomit是一款超赞的演示辅助工具.具有屏幕缩放.屏幕画笔.倒计时功能.且无需安装,点开即用. 1. 屏幕缩放 Ctrl + ...