Created
December 31, 2020 16:44
-
-
Save bobfang1992/69453c6d942818e20f6d7f8a243da1a5 to your computer and use it in GitHub Desktop.
Leetcode 84
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def largestRectangleArea(self, heights: List[int]) -> int: | |
stack = [-1] | |
result = 0 | |
heights.append(0) | |
for i in range(len(heights)): | |
while stack and heights[stack[-1]] > heights[i]: | |
h = heights[stack.pop()] | |
w = i - stack[-1] - 1 | |
# print(h, w) | |
result = max(result, h * w) | |
stack.append(i) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment