https://leetcode.com/problems/container-with-most-water/
这道题采用对撞指针的思路,从两侧向中间逼近,逼近的过程中,每次选择较低的一面墙
代码语言:javascript复制class Solution {
public:
int maxArea(vector<int>& height) {
auto lp = height.begin();
auto rp = height.end()-1;
int res = 0;
int area = 0;
while(lp!=rp){
area = min((*lp),(*rp))*(distance(lp,rp));
res = max(res,area);
if(*lp<*rp){
lp ;
}
else{
rp--;
}
}
return res;
}
};