auto-generated entry for Assign Cookies. the solution files are available below.
solution files
- C++
assign-cookies/synced-solution.cpp - Python
assign-cookies/synced-solution.py - TypeScript
assign-cookies/synced-solution.ts
Collected C++, Python, TypeScript solutions for assign cookies. Add a dedicated write-up later if you want deeper notes.
auto-generated entry for Assign Cookies. the solution files are available below.
assign-cookies/synced-solution.cppassign-cookies/synced-solution.pyassign-cookies/synced-solution.tsdef findContentChildren(g, s):
g.sort()
s.sort()
child = class="syntax-number">0
cookie = class="syntax-number">0
while child < len(g) and cookie < len(s):
if s[cookie] >= g[child]:
child += class="syntax-number">1
cookie += class="syntax-number">1
return child
class Solution {
public:
int findContentChildren(vector<int>& g, vector<int>& s) {
sort(g.begin(), g.end());
sort(s.begin(), s.end());
int child = class="syntax-number">0, cookie = class="syntax-number">0;
while (child < g.size() && cookie < s.size()) {
if (s[cookie] >= g[child]) {
child++;
}
cookie++;
}
return child;
}
};
function findContentChildren(g: number[], s: number[]): number {
g.sort((a, b) => a - b);
s.sort((a, b) => a - b);
let child = class="syntax-number">0, cookie = class="syntax-number">0;
while (child < g.length && cookie < s.length) {
if (s[cookie] >= g[child]) {
child++;
}
cookie++;
}
return child;
}