首页 > 其他分享 >LeetCode554 砖墙

LeetCode554 砖墙

时间:2022-09-26 22:14:14浏览次数:69  
标签:cnt cur wall len ans 砖墙 LeetCode554

LeetCode554 砖墙

哈希

class Solution:
    def leastBricks(self, wall: List[List[int]]) -> int:

        wall_len, cnt, m = sum(wall[0]), {}, len(wall)

        for i in range(m):
            cur = 0
            for j in range(len(wall[i]) - 1):

                cur = cur + wall[i][j]
                if cur in cnt: cnt[cur] += 1
                else: cnt[cur] = 1
        
        ans = m
        for i in cnt:
            val = 0 if i not in cnt else cnt[i]
            ans = min(ans, m - val)
        
        return ans

标签:cnt,cur,wall,len,ans,砖墙,LeetCode554
From: https://www.cnblogs.com/solvit/p/16732688.html

相关文章