kucheasysa

Algoverse_adesh_24

Jun 22nd, 2024
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. class Solution:
  2.     def surfaceArea(self, grid: List[List[int]]) -> int:
  3.         n = len(grid)
  4.         res = 0
  5.         for i in range(n):
  6.             rh = 0
  7.             ch = 0
  8.             for j in range(n):
  9.                 t = grid[i][j]
  10.                 res += 2 if t else 0
  11.                 res += abs(t - rh)
  12.                 rh = t
  13.                 t = grid[j][i]
  14.                 res += abs(t - ch)
  15.                 ch = t
  16.             res += rh + ch
  17.         return res
Advertisement
Add Comment
Please, Sign In to add comment