思想:
start初始指向0,end指向size-1;
若height[start]短,start++;
若height[end]短,end--;
即每次刷新最短的隔板。
class Solution {
public:
int maxArea(vector<int>& height) {
int start = 0;
int end = height.size() - 1;
int max = INT_MIN;
while(start < end) {
int area = (end-start) * min(height[start], height[end]);
max = area > max ? area : max;
if(height[start] >= height[end]) {
end--;
}else {
start++;
}
}
return max;
}
};