Leetcode-Easy 887. Projection Area of 3D Shapes

简介: Leetcode-Easy 887. Projection Area of 3D Shapes

题目描述


给出NN的网格grid,然后根据grid[i][j]的值在上面放置相应数量的11*1的立方体,然后求在xy,xz,yz三个平面投射的总面积


54.png


思路


当时自己没有想到好办法,就是按部就班的分别求三个面的面积,注意求xy的面积的时候需要考虑grid[i][j]值是否为0


代码实现



class Solution:
    def projectionArea(self, grid):
        """
        :type grid: List[List[int]]
        :rtype: int
        """
        # xy平面的面积
        size=len(grid)
        xy_area=0
        for i in range(size):
            for j in range(size):
                if grid[i][j]>0:
                    xy_area+=1
        # xz平面的面积
        xz_area=0
        temp_column=[]
        for i in range(size):
            for row in grid:
                temp_column.append(row[i])
            xz_area+=max(temp_column)
            temp_column=[]
        # yz平面的面积
        yz_area=0
        for i in range(size):
            yz_area+=max(grid[i])
        return xy_area+xz_area+yz_area


相关文章
200Echarts - 自定义系列(Use custom series to draw wind vectors)
200Echarts - 自定义系列(Use custom series to draw wind vectors)
47 0
135Echarts - 路径图(Use lines to draw 1 million ny streets.)
135Echarts - 路径图(Use lines to draw 1 million ny streets.)
50 0
Only Tensors of floating point and complex dtype can require gradients问题解决方案
Only Tensors of floating point and complex dtype can require gradients问题解决方案
472 0
Only Tensors of floating point and complex dtype can require gradients问题解决方案
|
数据挖掘 云计算 数据格式
跟着Cell学作图| 11.Ingenuity Pathway Analysis(IPA)
这篇2020年发表在cell上关于新冠的组学文章里面有大量的生信内容。今天带大家复现其中同一个软件(IPA)做的两张图。
806 0
跟着Cell学作图| 11.Ingenuity Pathway Analysis(IPA)
成功解决ValueError: Dimension 1 in both shapes must be equal, but are 1034 and 1024. Shapes are [100,103
成功解决ValueError: Dimension 1 in both shapes must be equal, but are 1034 and 1024. Shapes are [100,103
Leetcode-Easy 867.Transpose Matrix
Leetcode-Easy 867.Transpose Matrix
99 0
|
算法
Split Shape by Plane in OpenCASCADE
Split Shape by Plane in OpenCASCADE eryar@163.com Abstract. Sometimes you want to split a shape by plane or even split a shape by a B Spline surfac...
1754 0