-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.cpp
More file actions
34 lines (30 loc) · 749 Bytes
/
11.cpp
File metadata and controls
34 lines (30 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Problem : 11. Container With Most Water
// Link : https://leetcode.com/problems/container-with-most-water/
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int maxArea(vector<int>& height) {
int Area = 0;
int x1 = 0;
int x2 = height.size() - 1;
while(x1 != x2){
int newArea = (x2 - x1) * min(height[x1], height[x2]);
Area = max(newArea, Area);
if(height[x1] < height[x2]){
++x1;
continue;
}
--x2;
}
return Area;
}
};
int main() {
Solution ob;
vector<int> height{10,1,2,7,6,1,5};
cout << ob.maxArea(height);
return 0;
}