版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhoujiaping123/article/details/82817650
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;
};