做这道题要想清楚一件事就是 想要求最大储水量 是两边的小边乘以底长 而假设移动长的那一条边 不管怎么移动 高还是短的那一条边 还是没有变 所以想要更大储水量一定是移动短的那一条边
class Solution {
public:
int maxArea(vector<int>& height) {
vector<int>::iterator it1 = height.begin();
vector<int>::iterator it2 = height.end()-1;
int n;
int h;
int temp;
int maxn = 0;
while (it1 != it2) {
n = it2 - it1;
if (*it1 > *it2) {
temp = *it2*n;
--it2;
}
else {
temp = *it1*n;
++it1;
}
if (temp > maxn)maxn = temp;
}
return maxn;
}
};