###### Largest Rectangle in Histogram

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.

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

Solution I

### First solution comes to my mind is that For every rectangle, traverse all the rectangles before it and store current max area. If the height of current rectangle is less than or equals to next one, skip current rectangle to decrease time.

public class Solution {
public int largestRectangleArea(int[] height) {
if (height == null || height.length == 0)
return 0;

int max = 0;

for (int i = 0; i < height.length; i++) {

if (i + 1 < height.length && height[i] <= height[i + 1])
continue;

int min = height[i];

for (int j = i; j >= 0; j--) {
min = Math.min(min, height[j]);
int maxArea = min * (i - j + 1);

if (maxArea > max) {
max = maxArea;
}

}
}

return max;
}
}

#### LeetCode84 Largest Rectangle in Histogram java题解

2015-06-27 11:21:16

#### leetcode_question_85 Largest Rectangle in Histogram

2013-09-18 14:00:28

#### HDU 1506(Largest Rectangle in a Histogram)动态规划

2015-08-10 15:24:37

#### LeetCode --- 84. Largest Rectangle in Histogram

2015-04-03 17:07:41

#### hdu - 1506 - Largest Rectangle in a Histogram（dp / 单调栈）

2014-11-01 08:46:21

#### Largest Rectangle in Histogram -- LeetCode

2014-03-05 08:52:52

#### LeetCode（84） Largest Rectangle in Histogram

2015-12-21 15:34:05

#### POJ 2559 Largest Rectangle in a Histogram -- 动态规划

2014-03-06 09:25:29

#### LeetCode 84 Largest Rectangle in Histogram (Python详解及实现)

2017-08-09 15:34:40

#### POJ-2559-Largest Rectangle in a Histogram-单调栈

2015-08-25 22:37:11

## 不良信息举报

Largest Rectangle in Histogram