class Solution {
public int maxArea(int[] height) {
int n = height.length;
int l = 0;
int r = n - 1;
int max = Math.min(height[l],height[r]) *(r - l);
while(l < r){
while(height[l] <= height[r] && l < r){
l++;
max = Math.max(max,Math.min(height[l],height[r]) * (r - l));
}
while(height[r] < height[l] && l < r){
r--;
max = Math.max(max,Math.min(height[l],height[r]) * (r - l));
}
}
return max;
}
}
力扣最大盛水量
最新推荐文章于 2024-09-06 07:19:40 发布