My simple c++ solution(45ms)


  • 0
    C

    ....
    class Solution {
    public:
    int findContentChildren(vector<int>& g, vector<int>& s) {
    int Max=0;
    int Kid_Num=g.size();
    int Cookie_Num=s.size();
    sort(g.begin(),g.end());
    sort(s.begin(),s.end());
    int i=0;
    int j=0;
    if(Kid_Num==0 || Cookie_Num==0)
    {
    return 0;
    }
    while(i!=Kid_Num && j!=Cookie_Num)
    {
    if(s[j]>=g[i])
    {
    i++;
    j++;
    Max++;
    }
    else
    {
    j++;
    }
    }
    return Max;
    }
    };
    ....


Log in to reply
 

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