题目如下:

【leetcode】883. Projection Area of 3D Shapes

【leetcode】883. Projection Area of 3D Shapes

解题思路:分别求出所有立方体的个数,各行的最大值之和,各列的最大值之和。三者相加即为答案。

代码如下:

class Solution(object):
    def projectionArea(self, grid):
        """
        :type grid: List[List[int]]
        :rtype: int
        """
        front = [0] * len(grid)
        side = [0] * len(grid)
        top = 0
        for i in range(len(grid)):
            for j in range(len(grid[i])):
                if grid[i][j] == 0:
                    continue
                top += 1
                front[i] = max(front[i],grid[i][j])
                side[j] = max(side[j],grid[i][j])
        return top + sum(front) + sum(side)

 

相关文章:

  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
  • 2021-07-25
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2021-06-01
猜你喜欢
  • 2022-01-16
  • 2021-06-27
  • 2021-06-17
  • 2021-08-26
  • 2022-12-23
  • 2021-07-19
相关资源
相似解决方案