Skip to content

Commit 96e4f03

Browse files
authored
Merge pull request doocs#72 from bluesword12350/master
011.Container With Most Water (java)
2 parents d537ba4 + da0dc4b commit 96e4f03

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int maxArea(int[] height) {
3+
int start = 0, end = height.length - 1, maxArea = 0;
4+
while (start < end) {
5+
int hs = height[start];
6+
int he = height[end];
7+
int l = end - start;
8+
if (hs > he) {
9+
maxArea = Math.max(he * l, maxArea);
10+
end--;
11+
} else {
12+
maxArea = Math.max(hs * l, maxArea);
13+
start++;
14+
}
15+
}
16+
return maxArea;
17+
}
18+
}

0 commit comments

Comments
 (0)