cpp: add “455. Assign Cookies”
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
48847d9631
commit
9af5c9e61e
1 changed files with 21 additions and 0 deletions
21
cpp/assign-cookies.cpp
Normal file
21
cpp/assign-cookies.cpp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
int findContentChildren(std::vector<int> g, std::vector<int> s) {
|
||||||
|
std::sort(g.begin(), g.end());
|
||||||
|
std::sort(s.begin(), s.end());
|
||||||
|
|
||||||
|
int content = 0;
|
||||||
|
for (int i = 0, j = 0; i < g.size() && j < s.size(); ++j) {
|
||||||
|
if (g[i] <= s[j]) {
|
||||||
|
++i;
|
||||||
|
++content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue