def largestRectangleArea(self, heights: List[int]) -> int:
n, heights, st, ans = len(heights), [0] + heights + [0], [], 0
while st and heights[st[-1]] > heights[i]:
ans = max(ans, heights[st.pop(-1)] * (i - st[-1] - 1))
def maximalRectangle(self, matrix: List[List[str]]) -> int:
ans = max(ans, self.largestRectangleArea(heights))