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