Skip to content

Commit 503d942

Browse files
committed
Container With Most Water
1 parent 2045239 commit 503d942

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

11.cpp

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

0 commit comments

Comments
 (0)