# 柱状图中最大的矩形

<p>给定 <em>n</em> 个非负整数，用来表示柱状图中各个柱子的高度。每个柱子彼此相邻，且宽度为 1 。</p><p>求在该柱状图中，能够勾勒出来的矩形的最大面积。</p><p>&nbsp;</p><p><img src="https://img-service.csdnimg.cn/img_convert/947ba982417b598ee8de378ac4b1c2bf.png"></p><p><small>以上是柱状图的示例，其中每个柱子的宽度为 1，给定的高度为&nbsp;<code>[2,1,5,6,2,3]</code>。</small></p><p>&nbsp;</p><p><img src="https://img-service.csdnimg.cn/img_convert/2873fce06be97533e2bc5b5384510f67.png"></p><p><small>图中阴影部分为所能勾勒出的最大矩形面积，其面积为&nbsp;<code>10</code>&nbsp;个单位。</small></p><p>&nbsp;</p><p><strong>示例:</strong></p><pre><strong>输入:</strong> [2,1,5,6,2,3]<strong><br />输出:</strong> 10</pre>

以下程序实现了这一功能，请你填补空白处内容：

```java
class Solution {
	public int largestRectangleArea(int[] heights) {
		int length = heights.length;
		if (length == 0) {
			return 0;
		}
		int maxSize = 0;
		for (int i = 0; i < length; i++) {
			int nowHeight = heights[i];
			int nowWidth = 0;
			for (int j = i; j < length; j++) {
				___________________;
				nowWidth++;
				if (maxSize < nowHeight * nowWidth) {
					maxSize = nowHeight * nowWidth;
				}
			}

		}
		return maxSize;
	}
}

```

## template

```java
class Solution {
	public int largestRectangleArea(int[] heights) {
		int length = heights.length;
		if (length == 0) {
			return 0;
		}
		int maxSize = 0;
		for (int i = 0; i < length; i++) {
			int nowHeight = heights[i];
			int nowWidth = 0;
			for (int j = i; j < length; j++) {
				if (heights[j] < nowHeight) {
					nowHeight = heights[j];
				}
				nowWidth++;
				if (maxSize < nowHeight * nowWidth) {
					maxSize = nowHeight * nowWidth;
				}
			}

		}
		return maxSize;
	}
}

```

## 答案

```java
if (heights[j] < nowHeight) {
	nowHeight = heights[j];
}
```

## 选项

### A

```java
if (heights[j] > nowHeight) {
	nowHeight = heights[j];
}
```

### B

```java
if (heights[j] >= nowHeight) {
	nowHeight = heights[j] + 1;
}
```

### C

```java
if (heights[j] < nowHeight) {
	nowHeight = heights[j] + 1;
}
```