-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMaxArea.java
More file actions
35 lines (22 loc) · 757 Bytes
/
Copy pathMaxArea.java
File metadata and controls
35 lines (22 loc) · 757 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
class Solution {
public int maxArea(int[] height) {
if (height.length <= 1) {
return 0;
}
int left = 0;
int right = height.length - 1;
int maxArea = 0;
while (true) {
maxArea = Math.max(maxArea, Math.min(height[right], height[left]) * (right - left));
if (height[right] >= height[left]) {
left++;
} else {
right--;
}
if (left == right) {
break;
}
}
return maxArea;
}
}