c++ beats 95%


  • 0
    K
    class Solution {
    public:
        int findContentChildren(vector<int>& g, vector<int>& s) {
            int res = 0, m = g.size(), n = s.size();
            sort(g.begin(), g.end());
            sort(s.begin(), s.end());
            for (int i = 0, j = 0; i < m && j < n; ++i, ++j) { // asign from the smallest size candy to see if can content a child
                while (j < n && s[j] < g[i]) ++j;
                if (j < n) ++res;
            }
            return res;
        }
    };
    

Log in to reply
 

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