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 ...
随机推荐
- 如何取消Visual Studio Browser Link
VS2013.2015新建MVC网站并浏览后,页面默认自动启用Browser Link功能 解决方法,只需要在web.config中添加配置节点即可 <appSettings> <a ...
- Oracle数据导入指定表空间
1. 打开工具Oracle SQL Plus 以dba身份登录sys用户 sqlplus /nologconn sys@url as sysdba 2. 创建用户并指定表空间 使用客户端工具或者Web ...
- 前端项目微金所1 - bootstrap模板,Compatible(兼容),Viewport(视口),条件注释,第三方依赖,MediaQuery媒体查询
前端项目微金所笔记1 基础的bootstrap模板 <!DOCTYPE html> <html lang="en"> <head> <me ...
- 3D 特征点概述(2)
还是紧接着上一文章的思路继续介绍3D特征点的基本概念问题,还是这个表格: Feature Name Supports Texture / Color Local / Global / Regional ...
- oracle查找重复记录-转
SELECT *FROM t_info aWHERE ((SELECT COUNT(*) FROM t_info WHERE Title = a.Title) &g ...
- Centos 7 查看电池电量信息
而不像 ubuntu 在 /proc/acpi/battery/BAT 中. 其中 capacity 参数就是当前电脑的剩余电量的百分比信息了
- 一、Bitcoin比特币与BlockChain区块链技术
一.比特币历史 2008 年 10 月 31 日,一个网名叫中本聪(英文翻译过来滴)的家伙发布比特币唯一的白皮书:<Bitcoin:A Peer-to-PeerElectronic Cash S ...
- Dapper的基本使用,Insert、Update、Select、Delete
简介 Dapper是.NET下一个micro的ORM,它和Entity Framework或Nhibnate不同,属于轻量级的,并且是半自动的.也就是说实体类都要自己写.它没有复杂的配置文件,一个单文 ...
- [hive] hiveql 基础操作
1. 显示当前的数据库信息 直接修改hive.site.xml ,永久显示 2. 建表,模糊显示表信息 drop table 表名称: --删除表 show tables ;--显示所有表 sh ...
- Keepalived 配置高可用集群
一.Keepalived 简介 (1) Keepalived 能实现高可用也能实现负载均衡,Keepalived 是通过 VRRP 协议 ( Virtual Router Redundancy Pro ...