Title
Portal LeeCode 11
answer
The idea of the double pointer is to reduce the scale of the problem. For the point with a small current boundary height, the optimal solution with this boundary as the boundary has been updated, so it can be removed to narrow the interval.
class Solution {
public:
int maxArea(vector<int>& height) {
int sz = height.size(), s = 0, t = sz - 1, res = 0;
while(s < t){
int m = min(height[s], height[t]);
res = max(res, (t - s) * m);
if(m == height[s]) ++s;
else --t;
}
return res;
}
};