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. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + c1_vcd4kpha + signature + MTA8L2NvZGU + l1_vcd4kpha + signature/Signature + CrXa0rvW1sfpv/fingerprint "" alt = "\">
The circular width from the right is the distance from the subscript to the rightmost, And the length is the height of the current column.
In the second case, if the current one is smaller than the previous one.
Then let the columns higher than this pillar out of the stack, and compare the maximum area of all the bars of the stack.
Public class Solution {public int largestRectangleArea (int [] height) {if (height = null | height. length = 0) return 0; int ans = 0; Stack
Stack = new Stack
(); For (int I = 0; I