mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
22 lines
687 B
C
22 lines
687 B
C
|
class Solution {
|
||
|
public:
|
||
|
int maxArea(vector<int>& height) {
|
||
|
int left = 0, right = height.size()-1;
|
||
|
int max = 0, temp = 0;
|
||
|
while(left < right) {
|
||
|
temp = (right - left) * (height[left] < height[right] ? height[left] : height[right]);
|
||
|
if(max < temp) max = temp;
|
||
|
if(height[left] < height[right]) {
|
||
|
do{
|
||
|
left++;
|
||
|
} while(left < right && height[left-1] >= height[left]);
|
||
|
}
|
||
|
else {
|
||
|
do{
|
||
|
right--;
|
||
|
} while(left < right && height[right] <= height[right+1]);
|
||
|
}
|
||
|
}
|
||
|
return max;
|
||
|
}
|
||
|
};
|