84. 柱状图中最大的矩形

https://leetcode-cn.com/problems/largest-rectangle-in-histogram/

84. 柱状图中最大的矩形

84. 柱状图中最大的矩形

方案:

https://leetcode-cn.com/problems/largest-rectangle-in-histogram/solution/84-by-ikaruga/

84. 柱状图中最大的矩形

 

class Solution:
    def largestRectangleArea(self, heights: List[int]) -> int:
        stacks = []
        max_value = 0
        heights = [0] + heights + [0]

        for i in range(len(heights)):
            while stacks and heights[stacks[-1]] > heights[i]:
                tmp_index = stacks.pop()
                tmp_value = heights[tmp_index]
                tmp_result = tmp_value * (i - stacks[-1] - 1)
                max_value = max(max_value, tmp_result)
            stacks.append(i)
        
        return max_value

 

上一篇:300PLCmpi转以太网通过CHNet-S7300在建材加工系统应用


下一篇:C#使用COM+实现事务控制,操作多个数据库