Skip to content

Commit 10a4916

Browse files
Create 11. Container_with_most_water.java
1 parent c115948 commit 10a4916

File tree

1 file changed

+23
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)