Assign Cookies LeetCode solution in C++

1
class Solution {
2
public:
3
int findContentChildren(vector<int> &g, vector<int> &s) {
4
sort(g.begin(),
5
g.end()); // sort the children's greed factors in non-decreasing order
6
sort(s.begin(), s.end()); // sort the cookie sizes in non-decreasing order
7
int contentChildren = 0;
8
int i = 0; // pointer to the current child's greed factor
9
int j = 0; // pointer to the current cookie size
10
while (i < g.size() && j < s.size()) {
11
if (s[j] >= g[i]) { // if the current cookie can satisfy the current
12
// child's greed factor
13
contentChildren++;
14
i++;
15
}
16
j++;
17
}
18
return contentChildren;
19
}
20
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0