Leetcode 84. Largest Rectangle in Histogram
题目
Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.
Example:
Input: [2,1,5,6,2,3]
Output: 10
解法1:Brutal force(TLE)
- 遍历所有interval
- 内部遍历interval记录minheight,并在每个位置计算maxarea
class Solution(object):
def largestRectangleArea(self, heights):
"""
:type heights: List[int]
:rtype: int
"""
maxarea = 0
n = len(heights)
for i in range(n):
minheight = float('inf')
for j in range(i,n):
minheight = min(minheight,heights[j])
maxarea = max(maxarea,minheight*(j-i+</