-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain11.java
More file actions
41 lines (37 loc) · 977 Bytes
/
Main11.java
File metadata and controls
41 lines (37 loc) · 977 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package HOT100;
public class Main11 {
public int maxArea(int[] height) {
int n = height.length;
int start=0, end=n-1;
int maxRL=0, area;
while(start<end){
area = (end-start) * Math.min(height[start], height[end]);
if(area>maxRL){
maxRL = area;
}
if(height[start]<height[end]){
start++;
}else{
end--;
}
}
return maxRL;
}
public static void main(String[] args) {
}
}
class Main11_1 {
public int maxArea(int[] height) {
int n = height.length;
int left = 0, right = n - 1, max = 0;
while (left < right) {
max = Math.max(max, Math.min(height[left], height[right]) * (right - left));
if(height[left] < height[right]) {
left ++;
} else {
right --;
}
}
return max;
}
}