MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / Solution

Class Solution

Array/SurfaceAreaOf3DShapes.py:50–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48"""
49
50class Solution(object):
51 def surfaceArea(self, grid):
52 """
53 :type grid: List[List[int]]
54 :rtype: int
55 """
56
57 result = 0
58
59 lengthY = len(grid)
60 lengthX = len(grid[0])
61
62 for i in range(lengthY):
63 for j in range(lengthX):
64 if grid[i][j] != 0:
65 temp_result = 6 * grid[i][j] - 2 * (grid[i][j] - 1)
66 left = min(grid[i][j-1], grid[i][j]) if j-1 >= 0 else 0
67 right = min(grid[i][j+1], grid[i][j]) if j+1 <= lengthX-1 else 0
68 up = min(grid[i-1][j], grid[i][j]) if i-1 >= 0 else 0
69 down = min(grid[i+1][j], grid[i][j]) if i+1 <= lengthY-1 else 0
70 result += (temp_result - sum([left, right, up, down]))
71 return result

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected