LeetCode题解(0554):砖墙(Python)
发布日期:2021-06-29 20:09:25 浏览次数:3 分类:技术文章

本文共 493 字,大约阅读时间需要 1 分钟。

题目:(中等)

标签:哈希表

解法 时间复杂度 空间复杂度 执行用时
Ans 1 (Python) O ( N ) O(N) O(N) : N为砖块总数 O ( N ) O(N) O(N) 204ms (94.75%)
Ans 2 (Python)
Ans 3 (Python)

解法一:

class Solution:    def leastBricks(self, wall: List[List[int]]) -> int:        total = len(wall)        interval = collections.Counter()        for w in wall:            now = 0            for n in w[:-1]:                now += n                interval[now] += 1        ans = interval.most_common(1)        return total - (ans[0][1] if ans else 0)

转载地址:https://dataartist.blog.csdn.net/article/details/109836629 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:LeetCode题解(0560):和为K的子数组(Python)
下一篇:LeetCode题解(0535):TinyURL的加密与解密(Python)

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月19日 04时54分54秒