AC Python clean solution using stack 76ms
def largestRectangleArea(self, height):\n        height.append(0)\n        stack = [-1]\n        ans = 0\n        for i in xrange(len(height)):\n            whi
    def largestRectangleArea(self, height):\n        height.append(0)\n        stack = [-1]\n        ans = 0\n        for i in xrange(len(height)):\n            while height[i] < height[stack[-1]]:\n                h = height[stack.pop()]\n                w = i - stack[-1] - 1\n                ans = max(ans, h * w)\n            stack.append(i)\n        height.pop()\n        return ans\n\n\n\n    # 94 / 94 test cases passed.\n    # Status: Accepted\n    # Runtime: 76 ms\n    # 97.34%\n\nThe stack maintain the indexes of buildings with ascending height. Before adding a new building pop the building who is taller than the new one. The building popped out represent the height of a rectangle with the new building as the right boundary and the current stack top as the left boundary. Calculate its area and update ans of maximum area. Boundary is handled using dummy buildings.
['Python']