C++ 8 lines sort + two pointers solution


  • 0
    int findContentChildren(vector<int>& g, vector<int>& s) {
            sort(g.begin(),g.end());
            sort(s.begin(),s.end());
            vector<int>::iterator greed=g.begin();
            vector<int>::iterator size=s.begin();
            while(greed!=g.end()&&size!=s.end()) 
                if(*greed<=*size) greed++,size++; 
                else size++;
            return greed-g.begin();
        }
    

Log in to reply
 

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