Skip to content

Commit e4733e2

Browse files
Merge pull request #28 from Arpiiitaaa/patch-2
Leetcode11-Container_With_Most_Water
2 parents 0991129 + 9f55f90 commit e4733e2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public:
3+
int maxArea(vector<int>& height)
4+
{
5+
int i=0, j=height.size()-1;
6+
int Soln=0;
7+
8+
while(i<j)
9+
{
10+
if(height[i] < height[j])
11+
{
12+
Soln = max(Soln, (j-i)*height[i]);
13+
i+=1;
14+
}
15+
else if(height[i] > height[j])
16+
{
17+
Soln = max(Soln, (j-i)*height[j]);
18+
j-=1;
19+
}
20+
else
21+
{
22+
Soln = max(Soln, (j-i)*height[i]);
23+
i+=1;
24+
j-=1;
25+
}
26+
}
27+
return Soln;
28+
}
29+
};

0 commit comments

Comments
 (0)