Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 15a6685

Browse files
authored
Create container_with_most_water.cpp
1 parent 7b10217 commit 15a6685

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cpp/container_with_most_water.cpp

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

0 commit comments

Comments
 (0)