码迷,mamicode.com
首页 > 其他好文 > 详细

栈的思想方法

时间:2015-11-04 17:33:13      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

 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

 

栈的思想方法

标签:

原文地址:http://www.cnblogs.com/zmy235/p/4936465.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!