My java solution


  • 0
    S
    public class Solution {
    public int maxArea(int[] height) {
        
        int left=0;
        int right=height.length-1;
        int water=0;
        while(left<=right)
        {
            int h = Math.min(height[left],height[right]);
            water=Math.max(water,h*(right-left));
            if(height[left]>height[right])
            {
                
                right--;
                while(right>=0&&height[right]<h)
                    right--;
            }
            else
            {
                left++;
                while(left<height.length&&height[left]<h)
                    left++;
            }
        }
        
        return water;
        
    }
    

    }


Log in to reply
 

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