我是靠谱客的博主 纯情篮球,这篇文章主要介绍LeetCode题解(1465):切割后面积最大的蛋糕(Python),现在分享给大家,希望可以做个参考。

题目:原题链接(中等)

标签:数组

解法时间复杂度空间复杂度执行用时
Ans 1 (Python) O ( H l o g H + V l o g V ) O(HlogH+VlogV) O(HlogH+VlogV) O ( l o g H + l o g V ) O(logH+logV) O(logH+logV)120ms (77.67%)
Ans 2 (Python)
Ans 3 (Python)

解法一:

class Solution:
    _MOD = 10 ** 9 + 7

    def maxArea(self, h: int, w: int, horizontalCuts: List[int], verticalCuts: List[int]) -> int:
        width, height = 0, 0

        horizontalCuts.sort()
        horizontalCuts.append(h)
        last = 0
        for n in horizontalCuts:
            height = max(height, n - last)
            last = n

        verticalCuts.sort()
        verticalCuts.append(w)
        last = 0
        for n in verticalCuts:
            width = max(width, n - last)
            last = n

        return width * height % self._MOD

最后

以上就是纯情篮球最近收集整理的关于LeetCode题解(1465):切割后面积最大的蛋糕(Python)的全部内容,更多相关LeetCode题解(1465):切割后面积最大内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部