容易得到当前体积和高度的min相关,移动更小的尝试得到更佳的答案。
class Solution {
public:
int maxArea(vector<int>& height) {
int left = 0, right = height.size()-1;
int maxn = 0;
while(left < right){
int mmin = height[left], flag=0;
if(height[right] < mmin )
mmin = height[right], flag=1;
maxn = maxn > mmin*(right - left) ? maxn : mmin*(right - left);
if(flag)
--right;
else
++left;
}
return maxn;
}
};