Java use 2 pointer O(n)


  • 1
    Z
    if (height.length < 2)   return -1;
    int res = 0, left = 0, right = height.length - 1, temp;
    while (left < right){
        if (height[left] < height[right])    temp = (right - left)*height[left++];
        else    temp = (right - left)*height[right--];
        if (temp >  res)   res = temp;
    }
    return res;
    

Log in to reply
 

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