# LeetCode之Largest Rectangle in Histogram

/*用栈维持一个不递减的数组的下标。用以获取某个连续段的最大矩形。

class Solution {
public:
int largestRectangleArea(vector<int>& height) {
if(height.empty()) return 0;
height.push_back(0);
stack<int> s;
int res(0), i(0);
while(i < height.size()){
if(s.empty() || height[i] >= height[s.top()]) s.push(i);//入栈
else{//出栈
int h = height[s.top()];
while(!s.empty() && height[i] < height[s.top()]){//出栈
if(height[s.top()] < h) h = height[s.top()];
int tmp = s.top();
s.pop();
res = max(res, (s.empty() ? i : i - s.top()-1)*h);
}
s.push(i);
}
++i;
}
return res;
}
};

• 本文已收录于以下专栏：

## LeetCode Largest Rectangle in Histogram

• 2015年06月22日 23:25
• 2.67MB
• 下载

## [leetcode] 84. Largest Rectangle in Histogram

Given n non-negative integers representing the histogram's bar height where the width of each bar i...

## leetcode No84. Largest Rectangle in Histogram

Question： Given n non-negative integers representing the histogram's bar height where the width o...

## LeetCode-84.Largest Rectangle in Histogram

Given n non-negative integers representing the histogram's bar height where the width of each bar is...

## leetcode84: Largest Rectangle in Histogram

84. Largest Rectangle in Histogram height的内容是 [5,6,7,8,3]，特点是除了最后一个，前面全部保持递增，且最后一个立柱的高度小于前面所有立柱高度。对...

## [LeetCode] 84. Largest Rectangle in Histogram

[LeetCode] 84. Largest Rectangle in HistogramGiven n non-negative integers representing the histogra...

## leetcode: Largest Rectangle in Histogram，Maximal Square，Maximal Square问题

Largest Rectangle问题题目描述Given n non-negative integers representing the histogram’s bar height where t...

举报原因： 您举报文章：LeetCode之Largest Rectangle in Histogram 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)