A Javascript solution


  • 3
    var maxArea = function(height) {
        var maxArea = 0;
        var length = height.length;
        var head = 0, tail = length-1;
        while (tail - head > 0){
            var area = Math.min(height[head],height[tail]) * (tail - head);
            maxArea = Math.max(maxArea, area);
            if (height[head] > height[tail]){
                tail--;
            }else{
                head++;
            }
            
        }
        return maxArea;
    };

Log in to reply
 

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