-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainer.java
More file actions
executable file
·27 lines (24 loc) · 735 Bytes
/
Copy pathContainer.java
File metadata and controls
executable file
·27 lines (24 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package array;
/**
* Created by Administrator on 2018/3/27 0027.
*/
public class Container {
public static int maxArea(int[] height) {
int size=height.length;
int max=Math.min(height[size-1],height[0])*(size-1);
int left=0;
int right=size-1;
while(left<right){
if(Math.min(height[right],height[left])*(right-left)>max)
max=Math.min(height[right],height[left])*(right-left);
if(height[left]<height[right])
left++;
else right--;
}
return max;
}
public static void main(String[] args) {
int []a={2,3,4,5,18,17,6};
System.out.println(maxArea(a));
}
}