首页 > 其他 > 详细

leetcode——84. 柱状图中最大的矩形

时间:2019-11-04 12:42:09      阅读:76      评论:0      收藏:0      [点我收藏+]
class Solution(object):
    def largestRectangleArea(self, heights):
        """
        :type heights: List[int]
        :rtype: int
        """
        stack = []
        heights = [0] + heights + [0]
        res = 0
        for i in range(len(heights)):
            #print(stack)
            while stack and heights[stack[-1]] > heights[i]:
                tmp = stack.pop()
                res = max(res, (i - stack[-1] - 1) * heights[tmp])
            stack.append(i)
        return res
执行用时 :108 ms, 在所有 python 提交中击败了69.00%的用户
内存消耗 :13.6 MB, 在所有 python 提交中击败了41.18%的用户
 
这道题不太会。。。。
 
——2019.11.4

leetcode——84. 柱状图中最大的矩形

原文:https://www.cnblogs.com/taoyuxin/p/11791167.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!