[leetcode]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.

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

对数组进行遍历:
对第一个元素 2 ,找2前后比2大的数,0个。面积=21=2
第二个元素 1,前后比1大的,有5个。面积 = 1
6 =6
第三个元素 5,有1个比5大的,面积 52 =10
第四个元素6,有0个比6大的,面积 = 6
1 =6
第五个元素2,有4个比2大的,面积 = 24 =8
第六个元素3,有0个比3大的,面积 = 3
1 =3

最大面积 10