455. Assign Cookies

PHOTO EMBED

Thu Feb 23 2023 14:19:50 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

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;
    }
};
content_copyCOPY

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