mirror of
https://git.wolves.top/wolves/leetcode.git
synced 2025-11-04 17:26:32 +08:00
init
This commit is contained in:
18
greed/11.h
Normal file
18
greed/11.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user