题目

11. 盛最多水的容器

答案

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution {
public:
int maxArea(vector<int>& height) {
int len = height.size();
int i = 0;
int j = len-1;
int maxResult = 0;
while(i<j){
if(height[i]<height[j]){
maxResult = max(maxResult,(j-i)*height[i++]);
}
else{
maxResult = max(maxResult,(j-i)*height[j--]);
}
}
return maxResult;
}
};

__END__