public int largestRectangleArea(int[] height) {
        int [] heights = new int[height.length+1];
        System.arraycopy(height, 0, heights, 0, height.length);
        Stack<Integer> stack = new Stack<Integer>();;
        int max = 0;
        for(int i = 0; i < heights.length; ++i){
            if(stack.size() == 0 || heights[i] >= heights[stack.peek()]) {
                stack.push(i);
            }
            else{
                while(stack.size() > 0 && heights[i] <= heights[stack.peek()]){
                    int idx = stack.pop();
                    max = Math.max(max, (stack.size() > 0 ?(i - stack.peek() - 1) : i) * heights[idx]);
                }
                stack.push(i);
            }
        }
        return max;
    }