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.

Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].

The largest rectangle is shown in the shaded area, which has area = 10 unit.

For example,
Given heights = [2,1,5,6,2,3],
return 10.

class Solution {
public:
int largestRectangleArea(vector<int>& heights) {
heights.push_back();
stack<int> s;
int res = ;
int i = ;
while(i < heights.size()){
if(s.empty() || heights[i] > heights[s.top()]){
s.push(i);
i++;
}else{
int cur = s.top();
s.pop();
if(s.empty()){
res = max(res,heights[cur]*i);
}else{
res = max(res,heights[cur]*(i-s.top()-));
}
}
}
return res; }
};

最新文章

  1. C# 给PDF文件添加水印
  2. RecyclerView-------MainActivity代码
  3. poj 3278:Catch That Cow(简单一维广搜)
  4. 使用 Responsive Elements 快速构建响应式网站
  5. uva 10564
  6. SQL-学习使用FOR XML PATH
  7. 严重: The web application [] registered the JDBC driver 错误
  8. [Google Code Jam (Round 1A 2008) ] A. Minimum Scalar Product
  9. 关于css的优先级
  10. (函数封装)获取class名称
  11. 【Android Developers Training】 71. 显示翻牌动画
  12. Java中如何封装自己的类,建立并使用自己的类库?
  13. thymeleaf的配置
  14. awk命令基本使用方法
  15. CentOS系统实现SSH无密码登录的方法
  16. 1 认识开源性能测试工具jmeter
  17. 尼克的任务(P1280)
  18. Linux内核中_IO,_IOR,_IOW,_IOWR宏的用法
  19. VBA学习笔记(9)--生成点拨(1)
  20. Qt中Pro文件变量详细说明

热门文章

  1. 在QtCreator 2.1.0 下使用opencv231库加载图片并显示
  2. eclipse + python dev
  3. windows平台下安装、编译、使用mongodb C++ driver
  4. 去除 UINavigationController.navigationBar下方的横线
  5. 移动混合开发之android文件管理--&gt;flexbox,webFont。
  6. jpa遇到的 org.hibernate.PersistentObjectException: detached entity passed to persist异常
  7. 实验二 简易版C语言文法
  8. java语法基本知识
  9. C# StreamReader
  10. Best Coder Round#25 1001 依赖检测