algorithmic-studies/leetcode/leetcode_554.py

25 lines
652 B
Python

class Solution(object):
def leastBricks(self, wall):
"""
:type wall: List[List[int]]
:rtype: int
"""
cuts = dict()
rowSum = 0
# get all possible cutss
for row in wall:
rowSum = 0
for brick in row:
rowSum += brick
if rowSum not in cuts:
cuts[rowSum] = 0
cuts[rowSum] += 1
amountBestCut = 0
for cut, amount in cuts.items():
if amount > amountBestCut and cut != 0 and cut != rowSum:
amountBestCut = amount
return len(wall) - amountBestCut