We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 04e0517 commit 9418c21Copy full SHA for 9418c21
cpp/_11.cpp
@@ -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