Skip to content

Commit 6cb84b6

Browse files
committed
11. Container With Most Water
1 parent ba3622d commit 6cb84b6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

container-with-most-water.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//Runtime: 19 ms
2+
class Solution {
3+
public:
4+
int maxArea(vector<int>& height) {
5+
int lo = 0;
6+
int hi = height.size() - 1;
7+
int res = INT_MIN;
8+
while (lo < hi) {
9+
res = max(res, (hi - lo) * min(height[hi], height[lo]));
10+
11+
if (height[lo] < height[hi])
12+
lo++;
13+
else
14+
hi--;
15+
}
16+
return res;
17+
}
18+
};

0 commit comments

Comments
 (0)