Easy understanding java solution


  • 1
    C
    public int maxArea(int[] height) {
            if(height.length <= 0 || height == null) return 0;
            int area = 0;
            int left = 0;
            int right = height.length - 1;
            while(left < right) {
                int minHeight = Math.min(height[left], height[right]);
                area = Math.max(area,((right - left) * minHeight));
                if(height[left] <= height[right]) left++;
                else right--;
            }
            return area;
        }

Log in to reply
 

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