LeetCode之Largest Rectangle in Histogram浅析
首先上题目

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.
For example,
Given height = [2,1,5,6,2,3],
return 10.
题目的大意即给出一个柱状图的歌数据,求柱状图内所包含的最大矩形。
这道题目想了较长时间,助教说用栈的思想一开始也不是很明白(看来真的把数据结构灵活用到实际问题还是很难啊)。后来想用栈的话,目标肯定是O(n),基础操作不外乎前后项比较,根据比较结果进行不同操作,然后有了以下思路。
思路一
初始图表数据项是无序的,用栈进行操作剪掉非最优解后,我们要实现一个逐项递增的效果,如:1 1 1 2 2 4 4……这样的图表无疑是易于计算的。之所以用栈是因为,可以比较得出一个数据n的前后连续数据中,有几个不小于n,压栈完成了前计数,退栈完成了后计数。
LeetCode之Largest Rectangle in Histogram浅析的更多相关文章
- LeetCode 84. Largest Rectangle in Histogram 单调栈应用
LeetCode 84. Largest Rectangle in Histogram 单调栈应用 leetcode+ 循环数组,求右边第一个大的数字 求一个数组中右边第一个比他大的数(单调栈 Lee ...
- leetcode之Largest Rectangle in Histogram
问题来源:Largest Rectangle in Histogram 问题描述:给定一个长度为n的直方图,我们可以在直方图高低不同的长方形之间画一个更大的长方形,求该长方形的最大面积.例如,给定下述 ...
- Java for LeetCode 084 Largest Rectangle in Histogram【HARD】
For example, Given height = [2,1,5,6,2,3], return 10. 解题思路: 参考Problem H: Largest Rectangle in a Hist ...
- 关于LeetCode的Largest Rectangle in Histogram的低级解法
在某篇博客见到的Largest Rectangle in Histogram的题目,感觉蛮好玩的,于是想呀想呀,怎么求解呢? 还是先把题目贴上来吧 题目写的很直观,就是找直方图的最大矩形面积,不知道是 ...
- [LeetCode] 84. Largest Rectangle in Histogram 直方图中最大的矩形
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- [LeetCode OJ] Largest Rectangle in Histogram
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- [LeetCode#84]Largest Rectangle in Histogram
Problem: Given n non-negative integers representing the histogram's bar height where the width of ea ...
- LeetCode 84. Largest Rectangle in Histogram 直方图里的最大长方形
原题 Given n non-negative integers representing the histogram's bar height where the width of each bar ...
- [leetcode]84. Largest Rectangle in Histogram直方图中的最大矩形
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
随机推荐
- <2016-1-28>
1.链接的网址前加入?action=bs-transfer@mdp&url=http://www.baidu.com 2.登录页面的验证 <script> function log ...
- (Array)121. Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- rpm命令
RPM 安装.卸载.升级.查询和验证. RPM 安装 命令: rpm -i 文件名 如: rpm -i example.rpm 安装 example.rpm 包: rpm -iv example.rp ...
- VisualStudio2010正则表达式查找和替换
把 TRACE(_T("something etc."); 替换为 TRACE(_T("something etc."));查找内容:表达式:TRACE\(_T ...
- VMWare虚拟机 使用vmtools拷贝文件 临时文件问题
Win7下, 临时文件会存放在路径C:\Users\admin\AppData\Local\Temp\vmware-admin\VMwareDnD,如果不及时删除,C盘就会越来越大直至放满.
- c++学习--面向对象一
类与对象一 一 注意的点 1 利用构造函数给数据成员初始化的两种办法:1 赋值语句,2 用成员初始化列表 解释:1 成员初始化列表的一般形式为: 数据成员名1(初始值1),数据成员名2(初始值2) 2 ...
- AX7: Install a deployable package
Table of Contents Introduction Key concepts Collect topology configuration data Generate a runbook f ...
- Salesforce 动态审批
由于Salesforce只支持根据条件动态选择审批分支,如果我们想进一步支持动态根据页面的某种条件选择审批人,Salesforce是不支持的.因此我们只能通过override salesforce审批 ...
- ARM仿真器
ARM仿真器需要将调试换成simulator,其他JLink设置不变.否则会提示无法装载.flash文件 在keil下开发的设置
- Maximo子表中增加附件功能
附件功能的实现(详见ewell.webclient.beans.warranty.WarrantysDateBean ,ewell.webclient.beans.doclinks.custom.Ad ...