forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxArea.cpp
More file actions
47 lines (43 loc) · 1.02 KB
/
maxArea.cpp
File metadata and controls
47 lines (43 loc) · 1.02 KB
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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
class Solution {
public:
int maxArea(vector<int> &height) {
int ret = 0;
int lt = 0, rt = height.size() - 1;
while (lt < rt) {
ret = max(ret, (rt - lt) * min(height[lt], height[rt]));
if (height[lt] < height[rt]) ++lt;
else --rt;
}
return ret;
}
};
int main() {
Solution s = Solution();
vector<int> mm;
mm.push_back(3);
mm.push_back(2);
mm.push_back(1);
mm.push_back(3);
cout << s.maxArea(mm) << endl;
mm.clear();
// 10,14,10,4,10,2,6,1,6,12
mm.push_back(10);
mm.push_back(14);
mm.push_back(10);
mm.push_back(4);
mm.push_back(10);
mm.push_back(2);
mm.push_back(6);
mm.push_back(1);
mm.push_back(6);
mm.push_back(12);
cout << s.maxArea(mm) << endl;
return 0;
}