Skip to content

Commit b692573

Browse files
committed
Container With Most Water
1 parent ac76878 commit b692573

File tree

1 file changed

+24
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)