LeetCode/NeetCodeRoadmap/Stack/tempCodeRunnerFile.py
2023-10-02 21:05:36 -07:00

10 lines
303 B
Python

stack = [-1]
ans = 0
for i in xrange(len(height)):
while height[i] < height[stack[-1]]:
h = height[stack.pop()]
w = i - stack[-1] - 1
ans = max(ans, h * w)
stack.append(i)
height.pop()
return ans