39ms C++ Solution


  • 1
    N

    0_1485365067837_QQ截图20170126011931.png ![alt text]

     int findContentChildren(vector<int>& g, vector<int>& s) {
            int *gf = new int[g.size()], *cs = new int[s.size()], child = 0, cookie = 0;
            for(int i = 0; i < g.size(); i ++) gf[i] = g[i];
            for(int i = 0; i < s.size(); i ++) cs[i] = s[i];
            sort(gf, gf + g.size());
            sort(cs, cs + s.size());
            while(child < g.size() && cookie < s.size()){
                if(gf[child] <= cs[cookie]){
                    child ++; 
                }
                cookie ++;
            }
            return child;
        }
    

    Because using a vector is inefficient, I construct two array to deal with it.


Log in to reply
 

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