public static int largestRectangleArea(int[] height) {
        int len = height.length;
        if(len == 0) {
        	return 0;
        }else {
        	int[] h = Arrays.copyOf(height, len+1);
        	h[len] = 0;
        	Stack<Integer> stack = new Stack<Integer>();
        	int last = h[0];
        	stack.push(0);
        	int maxArea = 0;
        	for(int i=1;i<len+1;i++) {
        		if(h[i] >= last) {
        			stack.push(i);
        			last = h[i];
        		}else {
        			int leftStart = 0;
        			while(!stack.empty()) {
        				int leftStartPosition = stack.peek();
        				
        				int tmpArea = leftStart * (i-leftStartPosition-1);
    					if(tmpArea>maxArea) {
    						maxArea = tmpArea;
    					}
        				if(h[leftStartPosition] > h[i]) {
        					leftStart = h[leftStartPosition];
        					stack.pop();
        					tmpArea = leftStart * (i-leftStartPosition);
        					if(tmpArea>maxArea) {
        						maxArea = tmpArea;
        					}
        				}else {
        					break;
        				}
        			}
        			if(stack.empty()) {
        				int tmpArea = leftStart * (i);
    					if(tmpArea>maxArea) {
    						maxArea = tmpArea;
    					}
        			}
        			stack.push(i);
        			last = h[i];
        		}
        	}
        	return maxArea;
        	
        	        		
        }
       
    }