public int largestRectangleArea(int[] height) {
        Stack<Integer> stack = new Stack<Integer>();
        int result = 0;
        int len = height.length;
        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 sum = height[index] * (stack.isEmpty() ? i : i - stack.peek() - 1);
                result = Math.max(sum, result);
                i--;
            }
        }
        while(!stack.isEmpty()){
            int index = stack.pop();
            int sum = height[index] * (stack.isEmpty() ? len : len - stack.peek() - 1);
            result = Math.max(sum, result);
        }
        return result;
    }