第一种解法本质上是常规思路的优化
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