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. 【转】WPF绑定模式

    源地址:http://www.cnblogs.com/zjz008/archive/2010/05/26/1744802.html http://blog.csdn.net/haylhf/articl ...

  2. pandas空值处理与插值

    # coding:utf-8 import pandas as pd import numpy as np import matplotlib.pyplot as plt from scipy.int ...

  3. Velocity VelocityEngine 支持多种loader 乱码问题

    最近升级团队的代码生成工具,此工具是velocity实现的. 之前习惯使用UTF-8编码,现在团队使用GBK. 所以遇到一种场景,模板文件使用UTF-8(习惯了所有任性),输出文件使用GBK(项目需要 ...

  4. [转]激活函数ReLU、Leaky ReLU、PReLU和RReLU

    “激活函数”能分成两类——“饱和激活函数”和“非饱和激活函数”. sigmoid和tanh是“饱和激活函数”,而ReLU及其变体则是“非饱和激活函数”.使用“非饱和激活函数”的优势在于两点:    1 ...

  5. sqlite3 的insert记录项思路

    sqlite3 的insert记录项思路 1.组合一个insert的sql语句 2.判断是否需要立即执行,若不是立刻执行的语句,则插入到待处理的链表中,供后续事务处理时提交.必须有一个专门线程来对事务 ...

  6. 双机/RAC/Dataguard的区别【转】

    本文转自 双机/RAC/Dataguard的区别-jasoname-ITPUB博客 http://blog.itpub.net/22741583/viewspace-684261/ Data Guar ...

  7. 打包egg

    scrapyd-deploy -p chahao -v 1.0 --build-egg chahao.egg

  8. Django-模板语言和过滤器

    Django模板语言 首先模板只是一个文本文件,它可以生成任何基于文本的格式(HTML.XML.CSS等),模板中包含变量,在模板被渲染的时候替换为最终的值,以及控制模板逻辑的标签. 变量使用{{ 变 ...

  9. Python-Web框架的本质

    Web框架的本质 我们可以这样理解:所有的Web应用本质上就是一个socket服务端,而用户的浏览器就是一个socket客户端. 这样我们就可以自己实现Web框架了. Python中使用socket和 ...

  10. Python大数据处理案例

    分享 知识要点:lubridate包拆解时间 | POSIXlt利用决策树分类,利用随机森林预测利用对数进行fit,和exp函数还原 训练集来自Kaggle华盛顿自行车共享计划中的自行车租赁数据,分析 ...