public int largestRectangleArea(int[] height) {
        int max = 0;
        if(height.length ==0) return 0;
        
        int[] nh = Arrays.copyOf(height, height.length+1);
        nh[height.length] = 0;
         	    	
    	Stack<Integer> large = new Stack<Integer>();

    	for(int i=0; i<nh.length; i++)
    	{
    		if(large.isEmpty() ||nh[i]>=nh[large.peek()])
    		{
    			large.add(i);
    		}else
    		{
    			while(!large.isEmpty() && (nh[large.peek()]>nh[i] || large.peek() ==0))
    			{
    				int j=large.pop();
    				max = Math.max(max, (large.isEmpty()?i:(i-j))*nh[j]);
    				
    			}
    			large.add(i);
    		}
    	}
    	return max;
    }