设置两个指针i j ,分别指向首尾两块板,然后向中间移动,那么宽度变小的情况下为了增大面积只有让高度变大,所以每次移动所指板较低的指针,然后计算面积,重复以上过程。
int max(int a,int b){
return a > b ? a : b;
}
int maxArea(int* height, int heightSize) {
int l = 0, r = heightSize - 1;
int area = 0;
while(l < r){
if(height[l] < height[r]){
area = max(area,height[l]*(r-l));
l++;
}
else{
area = max(area,height[r]*(r-l));
r--;
}
}
return area;
}