I was stuck and took an eye on Geeks4Geeks. I got the idea and tried to figure it out by myself...

It takes me a lot of time to make it through....

**EDITED:** Now it is pretty concise....

```
public class Solution {
public int largestRectangleArea(int[] height) {
if (height==null) return 0;//Should throw exception
if (height.length==0) return 0;
Stack<Integer> index= new Stack<Integer>();
index.push(-1);
int max=0;
for (int i=0;i<height.length;i++){
//Start calculate the max value
while (index.peek()>-1)
if (height[index.peek()]>height[i]){
int top=index.pop();
max=Math.max(max,height[top]*(i-1-index.peek()));
}else break;
index.push(i);
}
while(index.peek()!=-1){
int top=index.pop();
max=Math.max(max,height[top]*(height.length-1-index.peek()));
}
return max;
}
```

}