MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / leastBricks

Method leastBricks

python/0554-brick-wall.py:2–11  ·  view source on GitHub ↗
(self, wall: List[List[int]])

Source from the content-addressed store, hash-verified

1class Solution:
2 def leastBricks(self, wall: List[List[int]]) -> int:
3 countGap = { 0 : 0 } # { Position : Gap count }
4
5 for r in wall:
6 total = 0 # Position
7 for b in r[:-1]:
8 total += b
9 countGap[total] = 1 + countGap.get(total, 0)
10
11 return len(wall) - max(countGap.values()) # Total number of rows - Max gap

Callers

nothing calls this directly

Calls 2

maxFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected