You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classSolution(object):
deflargestRectangleArea(self, heights):
""" :type heights: List[int] :rtype: int """# First point smaller than current point on the right sidestack, r_index= [], [len(heights)] *len(heights)
foriinrange(len(heights)):
whilestackandheights[i] <heights[stack[-1]]:
r_index[stack.pop()] =istack.append(i)
# First point smaller than current point on the left sidestack, l_index= [], [-1] *len(heights)
foriinrange(len(heights) -1, -1, -1):
whilestackandheights[i] <heights[stack[-1]]:
l_index[stack.pop()] =istack.append(i)
ans=0foriinrange(len(heights)):
ans=max(ans, heights[i] * (r_index[i] -l_index[i] -1))
returnans