Skip to content

Commit 9418c21

Browse files
committed
11.Container with most water.cpp solution file added
1 parent 04e0517 commit 9418c21

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cpp/_11.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// container-with-most-water
2+
// Problem Statement: https://leetcode.com/problems/container-with-most-water
3+
4+
#include<bits/stdc++.h>
5+
using namespace std;
6+
7+
class Solution {
8+
public:
9+
int maxArea(vector<int>& height) {
10+
if(height.size() < 1)
11+
return 0;
12+
13+
int left = 0;
14+
int right = height.size() - 1;
15+
int result = 0;
16+
17+
while(left < right){
18+
int area = (height[left] < height[right]) ? (height[left] * (right - left)) : (height[right] * (right -left));
19+
result = (area > result) ? area : result;
20+
(height[left] < height[right]) ? left++ : right--;
21+
}
22+
23+
return result;
24+
}
25+
};
26+

0 commit comments

Comments
 (0)