Skip to content

Commit 99861bc

Browse files
Add 0084_Largest_Rectangle_in_Histogram.py
1 parent bacb26b commit 99861bc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def largestRectangleArea(self, heights: List[int]) -> int:
3+
heights.append(0)
4+
lst = [-1]
5+
output = 0
6+
7+
for i in range(len(heights)):
8+
while (heights[i] < heights[lst[-1]]):
9+
height = heights[lst.pop()]
10+
width = i - lst[-1] - 1
11+
output = max(output, height * width)
12+
lst.append(i)
13+
14+
heights.pop()
15+
return output

0 commit comments

Comments
 (0)