class Solution {
public:
int CntArea(int i1, int i2, int val1, int val2){
return (i2 - i1)*(val1<val2? val1: val2);
}
int Cntmin(int i1, int i2, int val1, int val2){
return val1<val2? val1: val2;
}
int maxArea(vector<int>& height) {
int left = 0, right = height.size()-1;
//vector<int> max ;
int max = CntArea(left, right, height[left], height[right]);
int h = Cntmin(left, right, height[left], height[right]);
while(left < right){
if (height[left] == h){
while(left<right && height[left] <= h) left++;
h = Cntmin(left, right, height[left], height[right]);
max = (CntArea(left, right, height[left], height[right])>max? CntArea(left, right, height[left], height[right]): max);//若max更大,更新
}
else{ //height[right] == h
while(left<right && height[right] <= h) right--;
h = Cntmin(left, right, height[left], height[right]);
max = (CntArea(left, right, height[left], height[right])>max? CntArea(left, right, height[left], height[right]): max);
}
}
return max;
}
};