核心思想:双指针,数字小的那个指针移动
class Solution {
public:
int maxArea(vector<int>& height) {
int left = 0;
int right = height.size() - 1;
int maxArea = 0;
while ( left < right ) {
maxArea = max( min( height[left], height[right] ) * ( right - left ), maxArea );
if ( height[left] <= height[right] ) {
++left;
} else {
--right;
}
}
return maxArea;
}
};