-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path167_twoSumII.cpp
More file actions
48 lines (44 loc) · 971 Bytes
/
Copy path167_twoSumII.cpp
File metadata and controls
48 lines (44 loc) · 971 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
struct Bigger {
int x;
Bigger( int x) : x(x) {}
bool operator()( int num)
{
return num>=x;
}
};
int findContentChildren(vector<int>& g, vector<int>& s) {
sort(g.begin(), g.end());
sort(s.begin(), s.end());
int res = 0;
for (size_t i=0; i<g.size(); ++i)
{
std::vector<int>::iterator pos = find_if(s.begin(), s.end(), Bigger(g[i]) );
if (pos!=s.end())
{
++res;
s.erase(pos);
}
else
break;
}
return res;
}
};
int main()
{
Solution solution;
vector<int> nums;
nums.push_back(1);
nums.push_back(2);
nums.push_back(3);
vector<int> s(2,2);
int res = solution.findContentChildren(nums, s);
cout << res<< endl;
return 0;
}