leetcode-11. 盛最多水的容器
阿新 • • 發佈:2018-12-11
var maxArea = function(height) { let max = Math.min(height[0],height[1]) for(let i=2;i<height.length;i++){ for(let j=0;j<i;j++){ let h = Math.min(height[i],height[j]) max = Math.max(max,h*(i-j)); } } return max; };*/ var maxArea = function(height) { let i=0,j=height.length-1; let max = 0; while(i<j){ max = Math.max(max,Math.min(height[i],height[j])*(j-i)); if(height[i]<height[j]){ i++; }else{ j--; } } return max; };