Skip to content

Commit 17672bc

Browse files
Merge pull request PawanJaiswal08#20 from Vartika-Kulshreshtha/Container-With-Most-Water
Create 11. Container With Most Water
2 parents a68b973 + e67e309 commit 17672bc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

11. Container With Most Water

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

0 commit comments

Comments
 (0)