C++ short solution


  • 4
     int findContentChildren(vector<int>& g, vector<int>& s) {
            sort(g.begin(),g.end());
            sort(s.begin(),s.end());
            int i=g.size()-1, j=s.size()-1,count = 0;
            while(i>=0 && j>=0)
            {
                if(g[i]>s[j]) i--;
                else if(g[i--]<=s[j--]) count++;
            }
            return count;
        }
    

  • 0
    K
    This post is deleted!

  • 0
    int findContentChildren(vector<int>& g, vector<int>& s) {
            sort(g.begin(),g.end());
            sort(s.begin(),s.end());
            int i = 0;
            for(int j = 0; i < g.size() && j < s.size(); j++) i += g[i]<=s[j];
            return i;
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.