首页 > 其他 > 详细

84. Largest Rectangle in Histogram

时间:2020-06-02 10:37:18      阅读:37      评论:0      收藏:0      [点我收藏+]

第一种解法本质上是常规思路的优化

class Solution:
    def largestRectangleArea(self, heights: List[int]) -> int:
        length = len(heights)
        if length == 0:
            return 0
        if length == 1:
            return heights[0]
        result = 0
        for i in range(length):
            if i + 1 < length and heights[i] <= heights[i+1]:
                continue
            tmp = heights[i]
            for j in range(i,-1,-1):
                tmp = min(tmp, heights[j])
                area = (i-j+1)*tmp
                result = max(result, area)
        return result
                
                
        
        

  

 

84. Largest Rectangle in Histogram

原文:https://www.cnblogs.com/kingsleydev/p/13029145.html

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