Largest Rectangle in Histogram
2024-08-29 18:06:26
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; }
};
最新文章
- C# 给PDF文件添加水印
- RecyclerView-------MainActivity代码
- poj 3278:Catch That Cow(简单一维广搜)
- 使用 Responsive Elements 快速构建响应式网站
- uva 10564
- SQL-学习使用FOR XML PATH
- 严重: The web application [] registered the JDBC driver 错误
- [Google Code Jam (Round 1A 2008) ] A. Minimum Scalar Product
- 关于css的优先级
- (函数封装)获取class名称
- 【Android Developers Training】 71. 显示翻牌动画
- Java中如何封装自己的类,建立并使用自己的类库?
- thymeleaf的配置
- awk命令基本使用方法
- CentOS系统实现SSH无密码登录的方法
- 1 认识开源性能测试工具jmeter
- 尼克的任务(P1280)
- Linux内核中_IO,_IOR,_IOW,_IOWR宏的用法
- VBA学习笔记(9)--生成点拨(1)
- Qt中Pro文件变量详细说明
热门文章
- 在QtCreator 2.1.0 下使用opencv231库加载图片并显示
- eclipse + python dev
- windows平台下安装、编译、使用mongodb C++ driver
- 去除 UINavigationController.navigationBar下方的横线
- 移动混合开发之android文件管理-->;flexbox,webFont。
- jpa遇到的 org.hibernate.PersistentObjectException: detached entity passed to persist异常
- 实验二 简易版C语言文法
- java语法基本知识
- C# StreamReader
- Best Coder Round#25 1001 依赖检测