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. VSS+SourceAnywhere for VSS搭建版本控制系统教程

    VSS:Microsoft Visual Source Safe,本教程使用VSS2005(好像2005就是官方更新的最后一版了). SourceAnywhere for VSS:分为服务端和客户端: ...

  2. 使用web3+solc编译发布以太坊智能合约

    一.环境安装: 1.安装web3工程:npm install web3 2.安装solc工程:npm install solc二.在node环境中使用 先引用所需环境: var fs = requir ...

  3. Android studio 一个项目引入另一个项目作为Libary

    1.在我们开发Android项目时,有时需要一个项目作为另一个项目的工具类的引用,这样就需要配置下,使得MyLibrary到MyApplication作为一个module. 我们直接截图上步骤: 1. ...

  4. C#如何通过反射调用类下的方法

    首先模拟一个mvc的项目,创建一个业务类(HomeService),在类下创建3个方法 public class HomeService { /// <summary> /// 无参方法 ...

  5. @Configuration的使用 和作用

    1从spring4.0以后,@Spring boot Application就包含了@ComponentScan,@ComponentScan就不用写了 2@MapperScan(basePackag ...

  6. Easy and cheap cluster building on AWS backup

    https://grapeot.me/easy-and-cheap-cluster-building-on-aws.html Thu 17 July 2014 , by Yan Wang | 2 Co ...

  7. 研究Duilib的实现结构

    第一步:调用RegisterClassEx(): 第二步:调用CreateWindowEx() 第三步:调用ShowWindow(),同时启动消息循环 说明: 1.RegisterClass,Regi ...

  8. windows 日常使用

    打开任务管理器:shift+ctrl+esc 各种快捷打开的方式 regedit.msc 注册表 gpedit.msc 组策略 lusrmgr.msc本地用户和组 CMD命令窗口打开任务管理: tas ...

  9. datatime 模块

    import datetime # 这个是一个包 里面包含 对时间的处理 对日期的处理datetime.date # 日期相关datetime.time # 时间相关 # 获取当前详细时间print( ...

  10. SpringBoot document notes

    图片拷贝不过来,直接从github上下载 . 链接: https://github.com/DFX339/SpringBootDocumentNotes.git Create a example po ...