Share my python code. nothing special

  • 0
    class Solution:
        # @param height, a list of integer
        # @return an integer
        def largestRectangleArea(self, height):
            if not height:
                return 0
            stack = [(0,height[0])]
            maxsize = height[0] 
            for i in range(1, len(height)):
                start = i 
                while stack and stack[-1][1] > height[i]:
                    start = stack[-1][0]
                    size = stack[-1][1] * (i - stack[-1][0]) 
                    maxsize = max(size, maxsize)
                stack.append((start, height[i]))
            for s in stack:
                maxsize = max((len(height) - s[0]) * s[1], maxsize)
            return maxsize

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.