Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cookie that the child will be content with; and each cookie j has a size sj. If sj >= gi, we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.

题意:把m块饼干分给n个孩子,每块饼干的尺寸为mi,每个孩子的要求尺寸为ni,最多可以使几个孩子满足?

思路:

排序,目标只分饼干,从小到大遍历饼干,只要有某个饼干可以满足某个孩子,就立马把饼干分出去,如果某块饼干不能满足最小的需求尺寸,立马舍弃这块饼干

 class Solution(object):
def findContentChildren(self, g, s):
g.sort()
s.sort()
n,i = 0,0
for si in s:
if i == len(g):
break
if si >= g[i]:
n += 1
i += 1
return n

[leetcode greedy]455. Assign Cookies的更多相关文章

  1. 【leetcode】455. Assign Cookies

    problem 455. Assign Cookies solution1: But, you should give each child at most one cookie. 对小朋友的满意程度 ...

  2. 【LeetCode】455. Assign Cookies 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...

  3. LeetCode:455. Assign Cookies

    package Others; import java.util.Arrays; //Question 455. Assign Cookies /* Assume you are an awesome ...

  4. 455. Assign Cookies - LeetCode

    Question 455. Assign Cookies Solution 题目大意:数组g的大小表示有几个小孩,每个元素表示小孩的食量,数组s的大小表示有多少个饼干,每个元素的大小表示每个饼干的大小 ...

  5. LeetCode 455. Assign Cookies (分发曲奇饼干)

    Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...

  6. 12. leetcode 455.Assign Cookies

    Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...

  7. [LeetCode&Python] Problem 455. Assign Cookies

    Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...

  8. LeetCode 455. Assign Cookies (C++)

    题目: Assume you are an awesome parent and want to give your children some cookies. But, you should gi ...

  9. LeetCode: 455 Assign Cookies(easy)

    题目: Assume you are an awesome parent and want to give your children some cookies. But, you should gi ...

随机推荐

  1. 【Linux】SecureCRT连接Linux乱码

    SecureCRT连接linux出现乱码问题.解决方法. 打开SecureCRT-->option-->Session option

  2. 蓝牙4.0 BLE入门

    在BLE协议中有两个角色,一个是周边(Periphery),另外一个是中央(Central).一个中央可以同时连接多个周边,但一个周边某一时刻只能连接一个中央.但是不管periphery还是centr ...

  3. Eclipse中如何调整字体

    Eclipse 字体有两处,一处是控制台的字体,一处是主窗口.这里分别介绍控制台和主窗口字体的调节方法. Window -> Preferences -> General -> Ap ...

  4. NYOJ 119 士兵杀敌(三) (线段树)

    题目链接 描述 南将军统率着N个士兵,士兵分别编号为1~N,南将军经常爱拿某一段编号内杀敌数最高的人与杀敌数最低的人进行比较,计算出两个人的杀敌数差值,用这种方法一方面能鼓舞杀敌数高的人,另一方面也算 ...

  5. 对于Linux平台下C语言开发中__sync_函数的认识(转)

    reference:http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html#Atomic-Builtins A built-i ...

  6. ### mysql系统结构_3_Mysql_Learning_Notes

    mysql系统结构_3_Mysql_Learning_Notes 存储层,内存结构 全局(buferpool) 只分配一次 全局共享 连接/会话(session) 针对每个会话/线程分配 按需动态分配 ...

  7. pom可以过滤resource 下的文件

  8. RabbitMQ--Publish/Subscribe(四)

    先前例子中,我们创建了一个简单的日志系统,广播messages到consumer接收方. 但如果有日志错误级别的,不同的consumer接收不同错误级别的信息.比如consumer1接收info和wa ...

  9. dpr 与 dproj 有什么区别

  10. Java I/O系列汇总

    1.Java I/O---概述 2.Java I/O---File类 3.Java I/O---获取文件目录并写入到文本 4.Java I/O---输入与输出 5.Java I/O---复制文本文件 ...