LeetCode-84-Largest Rectangle in Histogram 经典题目,单调栈

class Solution(object):
    def largestRectangleArea(self, heights):
        """
        :type heights: List[int]
        :rtype: int
        """
        ans=0
        heights.append(0)
        stack=[]
        stack.append((0,-1))#(value,position)
        Len=len(heights)
        for i in range(Len):
            top=stack[-1]
            if heights[i]>top[0]:
                stack.append((heights[i],i))
            elif heights[i]

你可能感兴趣的:(Leetcode)