1 def largestRectangleArea(self, height): 2 height.append(0) 3 size = len(height) 4 no_decrease_stack = [0] 5 max_size = height[0] 6 i = 0 while i < size: 7 cur_num = height[i] 8 if (not no_decrease_stack or cur_num>height[no_decrease_stack[-1]]): no_decrease_stack.append(i) 9 i += 1 10 else: 11 index = no_decrease_stack.pop() 12 if no_decrease_stack: 13 width = i - no_decrease_stack[-1] - 1 14 else: 15 width = i 16 max_size = max(max_size, width * height[index]) 17 return max_size
时间: 2024-10-15 22:53:12