public class No11 {
public static void main(String[] args) {
int[] height = { 3, 4, 5 ,3};
System.out.println(maxArea(height));
}
public static int maxArea(int[] height) {
int left=0;
int right=height.length-1;
int max=0;
int size=0;
while(left<right){
size=(right-left)*Math.min(height[left], height[right]);
max=max>size?max:size;
if(height[left]>height[right])
right--;
else
left++;
}
return max;
}
}
11 Container With Most Water
最新推荐文章于 2022-09-30 07:29:10 发布