力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台
给定一个长度为
n的整数数组height。有n条垂线,第i条线的两个端点是(i, 0)和(i, height[i])。找出其中的两条线,使得它们与
x轴共同构成的容器可以容纳最多的水。返回容器可以储存的最大水量。
说明:你不能倾斜容器。
题解:
力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台
代码如下:
class Solution {
public int maxArea(int[] height) {
if(height.length == 0){
return 0;
}
int res = 0;
int i = 0, j = height.length - 1;
while(i < j){
if(height[i] < height[j]){
res = Math.max(res, (j-i) * height[i]);
i++;
}
else{
res = Math.max(res, (j-i) * height[j]);
j--;
}
}
return res;
}
}
1753

被折叠的 条评论
为什么被折叠?



