You are viewing a single comment's thread. Return to all comments →
Nice, here is a Python function that prints out the area:
def largestRectangle(h): h.append(0) stack = [] maxArea = (0, 0, 0, 0) for i, height in enumerate(h): j = i while stack and stack[-1][1] >= height: j, last = stack.pop() area = (i - j) * last if area > maxArea[0]: maxArea = (area, j, i, last) stack.append((j, height)) print maxArea return maxArea[0]
Seems like cookies are disabled on this browser, please enable them to open this website
Largest Rectangle
You are viewing a single comment's thread. Return to all comments →
Nice, here is a Python function that prints out the area: