leetcode 455. Assign Cookies

class Solution {
public:
    int findContentChildren(vector<int>& g, vector<int>& s) {
        sort(g.begin(),g.end());
        sort(s.begin(),s.end());
        int ans = 0;
        int i = g.size()-1;
        int j = s.size()-1;
        while(j >= 0){
            while(i >= 0 && g[i]> s[j])
                i--;
            if(i >= 0)
                ans++;
            j--;
            i--;
        }
        return ans;
    }
};

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章