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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy