【Java】 【笔记】leetcode11. 盛最多水的容器
//双指针法。存储水的多少取决于两端矮的柱子
class Solution {
public int maxArea(int[] height) {
int max = -1;
int left = 0;
int right = height.length - 1;
while(left < right){
int minHeight = height < height ? height : height;
int area = (right - left + 1)*minHeight;
max = Math.max(max,area);
}
return max;
}
} 领悟者的涂鸦笔 发表于 2021-3-19 15:48
a=
zuidazhi=0
for i in range(len(a)):
这种方式时间复杂度是O(n^2),可以优化
页:
[1]