At first I thought this problem should be solved by DP, but it is too complicated, so I just tried Greedy algorithm. One thing we should remember is that when we delivery our cookies, we should always satisfy the child with the smallest greedy factor, because this would save more cookies for the following delivery.

First we sort our **g** and **s**, and if there is a s[j] could satisfy g[i], we can add 1 to our result, otherwise we should stop and return our result, because for the following children, they will have more greedy factor than our current g[i].

```
class Solution {
public:
int findContentChildren(vector<int>& g, vector<int>& s) {
if(s.empty()) return 0;
sort(g.begin(), g.end());
sort(s.begin(), s.end());
int mg = g.size(), ns = s.size(), res = 0;
int i = 0, j = 0;
while(i < mg && j < ns){
while(j < ns && g[i] > s[j]){j++;}
if(j >= ns) break;
else{res++; i++; j++;}
}
return res;
}
};
```