JAVA---------------------Easy Version To Understand!!!!!!!!


  • 1
    H
    	public static int maxArea(int[] height) {
    	if (height == null || height.length == 0)
    		return 0;
    	int len = height.length;
    	int low = 0, high = len - 1, maxArea = -1;
    	while (low < high) {
    		int currentArea = (high - low) * (Integer.min(height[low], height[high]));
    		maxArea = Integer.max(maxArea, currentArea);
    		if (height[low] <= height[high])
    			low++;
    		else
    			high--;
    	}
    	return maxArea;
    }

Log in to reply
 

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