Java solution #two-pointer


  • 1
    public class Solution {
        public int maxArea(int[] height) {
            int l = 0;
            int r = height.length - 1;
            
            int max = 0;
            while (l < r) {
                int tmpMax = (r-l) * Math.min(height[l], height[r]);
                max = Math.max(tmpMax, max);
                
                if (height[l] <= height[r]) l++;
                else r--;
            }
            
            return max;
        }
    }
    

Log in to reply
 

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