https://leetcode.com/problems/assign-cookies/description/
Solution 1. sort and match
int findContentChildren(vector<int>& g, vector<int>& s) {
sort(g.begin(), g.end());
sort(s.begin(), s.end());
int res = 0;
for(int i=0,j=0;i<g.size()&&j<s.size();) {
if(g[i]<=s[j]) {
i++;j++;res++;
}
else
j++;
}
return res;
}
No comments:
Post a Comment