python codes using dict


  • 0
    C
    class Solution(object):
        def leastBricks(self, wall):
            """
            :type wall: List[List[int]]
            :rtype: int
            """
            dic = {}
            m = 0
            for row in wall:
                width = 0
                for i in range(len(row)-1):
                    width += row[i]
                    dic[width] = dic.get(width, 0)+1
                    if dic[width] > m:
                        m = dic[width]
            return len(wall)-m
    

Log in to reply
 

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