84. 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.
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.
求最大矩形的面积
方法一:暴力来leetcode上也能通过,方法也非常的好理解,就是遍历到每一个高度,向左和向右遍历,找到低于该高度的边界顺便计算矩形的宽度,进而计算面积,最终找到面积的最大值。
class Solution {
public:
int largestRectangleArea(vector<int>& heights) {
if(heights.size()&