思路:双指针
// @Title: 盛最多水的容器 (Container With Most Water)
// @Author: qisiii
// @Date: 2022-03-07 11:20:09
// @Runtime: 5 ms
// @Memory: 51.1 MB
// @comment: 双指针
// @flag: ORANGE
class Solution {
public int maxArea(int[] height) {
int max=0;
int left=0,right=height.length-1;
while(left<right){
int temp=(right-left)*Math.min(height[left],height[right]);
max=Math.max(temp,max);
if(height[left]<height[right]){
left++;
}else{
right--;
}
}
return max;
}
}
+++ title = “盛最多水的容器 (Container With Most Water)” draft = false +++
思路:
// @Title: 盛最多水的容器 (Container With Most Water)
// @Author: qisiii
// @Date: 2024-04-11 23:07:21
// @Runtime: 4 ms
// @Memory: 56.5 MB
// @comment:
// @flag:
class Solution {
public int maxArea(int[] height) {
int left=0,right=height.length-1;
int max=0;
while(left<right){
int area=(right-left)*Math.min(height[left],height[right]);
max=Math.max(max,area);
if(height[left]>height[right]){
right--;
}else{
left++;
}
}
return max;
}
}