Very short Java solution


  • -2
    Z
    public int largestRectangleArea(int[] height) {
    	int area=0;
    	int len = height.length;
    	for(int i=0;i<len;i++){
    		if(i==len-1 || height[i]>height[i+1]){
    			int stand = height[i];
    			for(int j=i;j>=0;j--){
    				if(height[j]<stand)
    					stand=height[j];
    				if(j==0|| height[j]>=height[j-1])
    					area = Math.max(area, stand*(i-j+1));				
    			}
    		}
    	}
        return area;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.