Preview:
class Solution {
public:
    int findContentChildren(vector<int>& g, vector<int>& s) {
        int n1=g.size();
        int n2=s.size();
        int i=0, j=0,res=0;
        sort(g.begin(),g.end());
        sort(s.begin(),s.end());
        while(i<n1 && j<n2)
        {
            if(g[i]<=s[j])
            {
                i++;j++;res++;
            }
            else
            {
                j++;
            }
        }
        return res;
    }
};
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter