On a N * N grid, we place some 1 * 1 * 1 cubes.

Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j).

Return the total surface area of the resulting shapes.

 

Example 1:

Input: [[2]]
Output: 10

Example 2:

Input: [[1,2],[3,4]]
Output: 34

Example 3:

Input: [[1,0],[0,2]]
Output: 16

Example 4:

Input: [[1,1,1],[1,0,1],[1,1,1]]
Output: 32

Example 5:

Input: [[2,2,2],[2,1,2],[2,2,2]]
Output: 46

Note:

  • 1 <= N <= 50
  • 0 <= grid[i][j] <= 50
class Solution(object):
def surfaceArea(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
allside=0
overlap=0 for i, v in enumerate(grid):
for j, z in enumerate(v):
if z==0:
continue allside+=4*z+2 if i!=0:
overlap+=min(z,grid[i-1][j])
if i!=len(grid)-1:
overlap+=min(z,grid[i+1][j])
if j!=0:
overlap+=min(z,grid[i][j-1])
if j!=len(grid[0])-1:
overlap+=min(z,grid[i][j+1]) return allside-overlap

  

[LeetCode&Python] Problem 892. Surface Area of 3D Shapes的更多相关文章

  1. [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 ...

  2. 【Leetcode_easy】892. Surface Area of 3D Shapes

    problem 892. Surface Area of 3D Shapes 题意:感觉不清楚立方体是如何堆积的,所以也不清楚立方体之间是如何combine的.. Essentially, compu ...

  3. 【LeetCode】892. Surface Area of 3D Shapes 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  4. [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 ...

  5. 892. Surface Area of 3D Shapes

    问题 NxN个格子中,用1x1x1的立方体堆叠,grid[i][j]表示坐标格上堆叠的立方体个数,求这个3D多边形的表面积. Input: [[1,2],[3,4]] Output: 34 思路 只要 ...

  6. 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 ...

  7. 【leetcode】892. Surface Area of 3D Shapes

    题目如下: 解题思路:对于v = grid[i][j],其表面积为s = 2 + v*4 .接下来只要在判断其相邻四个方向有没有放置立方体,有的话减去重合的面积即可. 代码如下: class Solu ...

  8. C#LeetCode刷题之#892-三维形体的表面积(Surface Area of 3D Shapes)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4136 访问. 在 N * N 的网格上,我们放置一些 1 * 1 ...

  9. [Swift]LeetCode892. 三维形体的表面积 | 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. Linux stress CPU的测试方法

    一.stress工具安装:1.获取stress源码安装包(stress-1.0.4.tar.gz)3.解压并安装 [root@localhost /]#cd /tmp/ [root@localhost ...

  2. CentOS配置教程

    1.配置网卡开机自动启动 查看/etc/sysconfig/network-scripts/ifcfg-eth0的初始内容: cat /etc/sysconfig/network-scripts/if ...

  3. Transactional参数说明

     参数  说明 readOnly 该属性用于设置当前事务是否为只读事务,设置为true表示只读,false则表示可读写,默认值为false.例如:@Transactional(readOnly=tru ...

  4. 中国队再创佳绩,IOI2018喜获四金

    第30届国际信息学奥林匹克竞赛(IOI2018)于9月1日-8日在日本筑波举行,共有来自87个国家(地区)的335名选手参赛.    中国代表队四名选手经过努力拼搏,获得金牌.其中,杨懋龙(湖南长沙市 ...

  5. Spring Boot + Druid 监控数据库(三)

    Druid可以做什么?  1) 可以监控数据库访问性能,Druid内置提供了一个功能强大的StatFilter插件,能够详细统计SQL的执行性能,这对于线上分析数据库访问性能有帮助. 2) 替换DBC ...

  6. 在学习DRF之前

    学习DRF之前~~~   在学习DRF之前~我们要先复习一些知识点~~ FBV和CBV 学习Django的时候~我们已经学习过了CBV以及FBV~~我们来复习一下~~ 什么是FBV和CBV呢~~ FB ...

  7. Centos7扩展存储空间

    1.在关机状态下,在Vm里面设置系统大小到需要的数值 :2.使用root权限登陆linux,df -h查看系统情况: [root@cratedb-hk-01 ~]# df -h 文件系统 容量 已用 ...

  8. day 36 关于io模型的问题 阻塞 和多路复用

    # from gevent import spawn,monkey;monkey.patch_all()# from socket import *# def server(ip,port):# se ...

  9. ios轮播图片用法

    // // ZQRViewController.m // 04-图片轮播器 // // Created by apple on 17-08-24. // Copyright (c) 2017年 zzq ...

  10. 24点小游戏app宣传文案

    24点小游戏app宣传文案 游戏背景 24点小游戏是传统的扑克牌游戏,是通过扑克牌来完成的竞争性智力游戏,除了希望能够消磨我们的空闲时间,加强同学们的临机和速算能力,还能够促进我们每个人的大脑和逻辑性 ...