Python


  • 0
    B
    class Solution(object):
        def leastBricks(self, wall):
            """
            :type wall: List[List[int]]
            :rtype: int
            """
            if len(wall) < 1  or len(wall[0]) < 1: return 0
            hashmap = {}
            for l in wall:
                last = 0
                for idx in range(len(l)-1):
                    if last+l[idx] not in hashmap:
                        hashmap[last+l[idx]] = -1
                    else:
                        hashmap[last+l[idx]] -= 1
                    last +=  l[idx]
            minoverlap = 0
            minoverlap = min(hashmap.values()) if hashmap else 0
            return len(wall) + minoverlap
    

Log in to reply
 

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