classSolution():deflargestRectangleArea(self, heights):
maxs = 0
reg = heights
n = len(reg)
i = 0
record = set(heights)
while i<n:
h = reg[i]
j1 = i
while j1>=0and reg[j1]>= h:
j1-=1
j2 = i
while j2<n and reg[j2]>=h:
j2+=1
s = (j2-j1-1)*reg[i]
maxs = max(s,maxs)
k = i+1while k<n and reg[k]==reg[i]:k+=1
i = k
return maxs
classSolution():deflargestRectangleArea(self, heights):
i,maxs = 0,0
s = []
heights.append(0)
while i< len(heights):
if len(s)==0or heights[i]>heights[s[-1]]:s.append(i);i+=1else:
t = heights[s.pop()]
maxs = max(maxs,t *(i if len(s)==0else (i-s[-1]-1)))
return maxs
#class Solution(): def largestRectangleArea(self, heights): i,maxs = 0,0 s = [] heights.append(0) while i< len(heights): if len(s)==0 or heights[i]>heigh