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
原文:https://www.cnblogs.com/taoyuxin/p/11791167.html