You are viewing a single comment's thread. Return to all comments →
Mine is quite similar but not completely.
def largestRectangle(h): stack = deque() max_area = 0 h += [0,] for i, n in enumerate(h): if not stack or n >= stack[-1][1]: stack.append((i, n)) else: while stack and stack[-1][1] >= n: p = stack.pop() max_area = max((i - p[0])*p[1], max_area) stack.append((p[0], n)) return max_area
Largest Rectangle
You are viewing a single comment's thread. Return to all comments →
Mine is quite similar but not completely.