1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public: int findContentChildren(vector<int>& g, vector<int>& s) { sort(g.begin(),g.end()); sort(s.begin(),s.end()); int count=0; for(int i=s.size()-1, gg=g.size()-1;i>=0&&gg>=0;i--,gg--,count++){ int ss=s[i]; while(gg>=0&&g[gg]>ss){ gg--; } if(gg<0) count--; } return count; } };
|