Clear Python Solution

  • 7
    class Solution(object):
        def leastBricks(self, wall):
            :type wall: List[List[int]]
            :rtype: int
            d = collections.defaultdict(int)
            for line in wall:
                i = 0
                for brick in line[:-1]:
                    i += brick
                    d[i] += 1
            # print len(wall), d
            return len(wall)-max(d.values()+[0])

  • 0

    This helped me a lot thanks. I almost had an identical answer, but I couldn't figure out how to return it. Subtracting from the length is what I needed and adding the [0] for the empty list is smart.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.