双指针问题,int left=0 right=heightsize-1;
int maxArea(int* height, int heightSize){
if(heightSize==1)
return 0;
int left=0;
int right=heightSize-1;
int maxsq=0;
while(left!=right){
int length=right-left;
int sq;
if(height[left]>height[right]){
sq=length*height[right];
right--;
}
else{
sq=length*height[left];
left++;
}
maxsq=(sq>maxsq)?sq:maxsq;
}
return maxsq;
}
作者:dzyy
链接:https://leetcode.cn/problems/container-with-most-water/solutions/792009/c-by-dzyy-zxs4/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。