-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (36 loc) · 1.01 KB
/
main.cpp
File metadata and controls
46 lines (36 loc) · 1.01 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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
int findContentChildren(vector<int>& g, vector<int>& s) {
sort(g.begin(), g.end(), greater<int>());
sort(s.begin(), s.end(), greater<int>());
int gi = 0, si = 0;
int res = 0;
while( gi < g.size() && si < s.size() ){
if( s[si] >= g[gi] ){
res ++;
si ++;
gi ++;
}
else
gi ++;
}
return res;
}
};
int main() {
int g1[] = {1, 2, 3};
vector<int> gv1(g1, g1 + sizeof(g1)/sizeof(int));
int s1[] = {1, 1};
vector<int> sv1(s1, s1 + sizeof(s1)/sizeof(int));
cout<<Solution().findContentChildren(gv1, sv1)<<endl;
int g2[] = {1, 2};
vector<int> gv2(g2, g2 + sizeof(g2)/sizeof(int));
int s2[] = {1, 2, 3};
vector<int> sv2(s2, s2 + sizeof(s2)/sizeof(int));
cout<<Solution().findContentChildren(gv2, sv2)<<endl;
return 0;
}