Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc0ae84

Browse files
commit
1 parent 54c43fc commit bc0ae84

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎11. Container With Most Water.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// Move the pointer pointing to the shorter line
12+
if (height[left] < height[right]) {
13+
left++;
14+
} else {
15+
right--;
16+
}
17+
}
18+
19+
return maxArea;
20+
}
21+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /