[力扣算法]《11. 盛最多水的容器》
class Solution {
// <11. 盛最多水的容器>
public int maxArea(int[] height) {
// 这个真的是秒杀!哈哈
//(上一题<986.区间列表的交集>官网题解的inspiration)
// 使用双指针解决
if(height.length==0)return 0;
if(height.length==1)return 0;
// if(height.length==2)return height[0] * height[1]; 临界条件判断错误!
int i = 0, j = height.length-1, ans = 0;
while(i<j){
ans = Math.max(ans, (j-i) * Math.min(height[i], height[j]));
if(height[i]<=height[j]){
i++;
}else{
j--;
}
}
return ans;
}
}