class Solution {
public:
int maxArea(vector<int>& height) {
int i=0;
int j=height.size()-1;
int res=0;
while(i < j){
if(height[i] < height[j]){
res = max(res, height[i] * (j - i));
i += 1;
}
else{
res = max(res, height[j] * (j - i));
j -= 1;
}
}
return res;
}
};
11. 盛最多水的容器(leetcode)
最新推荐文章于 2020-12-02 19:25:27 发布