题目
代码:双指针:O(n)
py:
class Solution:
def maxArea(self, height: List[int]) -> int:
ans = 0
i, j = 0, len(height)-1
while i < j:
ans = max(min(height[j], height[i])*(j-i), ans)
if height[i] >= height[j]:
j -= 1
else:
i += 1
return ans
C:
int maxArea(int* height, int heightSize){
int ans = 0;
int i = 0, j = heightSize - 1;
while(i < j){
ans = fmax(ans, fmin(height[i], height[j])*(j-i));
if(height[i] < height[j]){
i += 1;
} else{
j -= 1;
}
}
return ans;
}