Brick wall


  • 0
    S
    class Solution(object):
        def leastBricks(self, wall):
            """
            :type wall: List[List[int]]
            :rtype: int
            """
            ht = len(wall)
            wt = sum(wall[0])
            d = {}
    
            for row in wall:
                tot = 0
                for brick in row:
                    tot += brick
                    if tot < wt:
                        if tot in d:
                            d[tot] -= 1
                        else:
                            d[tot] = ht - 1
            
            l = list(d.values())
            l.append(ht)
            return min(l)
    

Log in to reply
 

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