Leetcode 554 Solution

This article provides solution to leetcode question 554 (brick-wall)

https://leetcode.com/problems/brick-wall

Solution

class Solution:
    def leastBricks(self, walls: List[List[int]]) -> int:
        m = collections.defaultdict(int)
        for wall in walls:
            cur = 0
            for i in range(0, len(wall) - 1):
                cur += wall[i]
                m[cur] += 1

        return len(walls) - (max(m.values()) if m else 0)