-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution1.java
More file actions
28 lines (25 loc) · 789 Bytes
/
Solution1.java
File metadata and controls
28 lines (25 loc) · 789 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
class Solution1 {
public int maxArea(int[] height) {
int start = 0;
int end = height.length - 1;
int max_cap = 0;
while(start < end){
int h = Math.min(height[start], height[end]);
int width = end - start;
int currentCap = h * width;
max_cap = Math.max(currentCap, max_cap);
if(height[start] < height[end]){
start++;
}
else{
end--;
}
}
return max_cap;
}
public static void main(String[] args) {
Solution1 solution = new Solution1();
int[] height = {1,8,6,2,5,4,8,3,7};
System.out.println(solution.maxArea(height)); // Output: 49
}
}