Java solution-two pointers


  • 0
    K

    public class Solution {
    public int maxArea(int[] height) {
    int lo=0;
    int hi=height.length-1;
    int area = less(height[lo],height[hi])(hi-lo);
    while(lo<hi)
    {
    if(height[lo]<height[hi])
    lo=lo+1;
    else
    hi=hi-1;
    int newarea=less(height[lo],height[hi])
    (hi-lo);
    if(newarea>area)
    area=newarea;
    }
    return area;

    }
    public int less(int lo,int hi){
            if(lo<=hi)
                return lo;
            else
                return hi;
        }
    

    }


Log in to reply
 

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