/
max_area.cpp
48 lines (40 loc) · 906 Bytes
/
max_area.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
int volumn(int x1, int y1, int x2, int y2)
{
return abs(x2-x1) * std::min(y1, y2);
}
int maxArea(vector<int> &height) {
int max = 0;
int vol = 0;
int l, r;
// if(height.size() < 2) return 0;
l = 0; r = height.size() - 1;
while(l > r)
{
vol = volumn(l, height[l], r, height[r]);
cout << vol <<endl;
max = std::max(max, vol);
if(height[l] < height[r])
{
l++;
}
else
{
r--;
}
}
return max;
}
};
int main()
{
cout << "Hello World" << endl;
Solution sol;
vector<int> vec = {1 , 1};
cout << sol.maxArea(vec) << endl;
return 0;
}