Skip to content

Commit 55ff889

Browse files
authored
Added java solution for 11_Container With Most Water (#124)
1 parent 267f983 commit 55ff889

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public int maxArea(int[] height) {
3+
int i = 0;
4+
int j = height.length - 1;
5+
6+
int maxArea = Integer.MIN_VALUE;
7+
8+
while(i < j) {
9+
int h = Math.min(height[i], height[j]);
10+
int width = j - i;
11+
12+
maxArea = Math.max(maxArea, h*width);
13+
14+
if(height[i] > height[j]) {
15+
j--;
16+
} else {
17+
i++;
18+
}
19+
20+
}
21+
22+
return maxArea;
23+
24+
}
25+
}

0 commit comments

Comments
 (0)