Skip to content

Commit

Permalink
Create 0554-Brick-Wall.py
Browse files Browse the repository at this point in the history
Create the Python solution as the same solution in the YouTube video "https://www.youtube.com/watch?v=Kkmv2h48ekw"
  • Loading branch information
MHamiid authored Jan 14, 2023
1 parent 0b13351 commit ceb0b45
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions python/0554-Brick-Wall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def leastBricks(self, wall: List[List[int]]) -> int:
countGap = { 0 : 0 } # { Position : Gap count }

for r in wall:
total = 0 # Position
for b in r[:-1]:
total += b
countGap[total] = 1 + countGap.get(total, 0)

return len(wall) - max(countGap.values()) # Total number of rows - Max gap

0 comments on commit ceb0b45

Please sign in to comment.