码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode "455. Assign Cookies"

时间:2017-01-24 13:38:54      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:public   mini   while   cookie   span   blog   simple   cookies   style   

Simple greedy thought .. satify each kid with minimum qualified cookie, from the least greedy kid..

class Solution {
public:
    int findContentChildren(vector<int>& g, vector<int>& s) {
        int ng = g.size();
        int ns = s.size();
        
        sort(g.begin(), g.end());
        sort(s.begin(), s.end());
        
        int ig = 0, is = 0;
        while(ig < ng && is < ns)
        {
            while(is < ns && s[is] < g[ig]) is ++;
            if(is == ns) break;
            
            ig ++; is ++;
        }
        
        return ig;
    }
};

LeetCode "455. Assign Cookies"

标签:public   mini   while   cookie   span   blog   simple   cookies   style   

原文地址:http://www.cnblogs.com/tonix/p/6346898.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!