Skip to content

Commit b14d1b3

Browse files
author
ChienkuChen
committed
Add 11
1 parent 1e8a5f0 commit b14d1b3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package _11;
2+
3+
class Solution {
4+
public int maxArea(int[] height) {
5+
int result = Integer.MIN_VALUE;
6+
int left = 0;
7+
int right = height.length - 1;
8+
9+
while (left < right) {
10+
int w = right - left;
11+
int h = Math.min(height[left], height[right]);
12+
result = Math.max(result, w * h);
13+
14+
if (h == height[left])
15+
left++;
16+
else
17+
right--;
18+
}
19+
20+
return result;
21+
}
22+
23+
public static void main(String[] args) {
24+
System.out.println(new Solution().maxArea(new int[]{1, 2, 3, 4, 5}));
25+
System.out.println(new Solution().maxArea(new int[]{5, 4, 3, 2, 1}));
26+
System.out.println(new Solution().maxArea(new int[]{7, 8, 3, 4, 2}));
27+
}
28+
}

0 commit comments

Comments
 (0)