Leetcode 455 Solution

This article provides solution to leetcode question 455 (assign-cookies)

https://leetcode.com/problems/assign-cookies

Solution

class Solution {
public:
    int findContentChildren(vector<int>& g, vector<int>& s) {
        sort(g.begin(), g.end());
        sort(s.begin(), s.end());

        int j = 0, i = 0;
        int total = 0;
        while (i < s.size() && j < g.size())
        {
            if (s[i] >= g[j])
                total++, i++, j++;
            else
                i++;
        }

        return total;
    }
};