JunyiCode
3/22/2020 - 10:53 PM

11. Container With Most Water

2 pointer

class Solution {
    public int maxArea(int[] nums) {
        if(nums == null || nums.length < 2) return 0;
        int low = 0, high = nums.length - 1;
        int res = Integer.MIN_VALUE;
        
        while(low < high) {
            int left = nums[low], right = nums[high];   
            if(left < right) {
                res = Math.max(res, (high - low) * left);
                low++;
            } else {
                res = Math.max(res, (high - low) * right);  
                high--;
            } 
        }
        
        return res;
    }
}