mirror of
https://git.wolves.top/wolves/leetcode.git
synced 2025-11-04 17:26:32 +08:00
18 lines
469 B
C
18 lines
469 B
C
#include <math.h>
|
|
|
|
// 核心优化,每次移动较小的那个,因为移动较大的那个,面积只会越来越小
|
|
int maxArea(int* height, int heightSize) {
|
|
int left = 0;
|
|
int right = heightSize - 1;
|
|
int max = 0;
|
|
while(left < right){
|
|
max = fmax(max,(right-left)*fmin(height[left],height[right]));
|
|
if (height[left] < height[right])
|
|
{
|
|
left++;
|
|
}else{
|
|
right--;
|
|
}
|
|
}
|
|
return max;
|
|
} |