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.

Note:
You may assume the greed factor is always positive. 
You cannot assign more than one cookie to one child.

Example 1:

Input: [1,2,3], [1,1]

Output: 1

Explanation: You have 3 children and 2 cookies. The greed factors of 3 children are 1, 2, 3.
And even though you have 2 cookies, since their size is both 1, you could only make the child whose greed factor is 1 content.
You need to output 1.

Example 2:

Input: [1,2], [1,2,3]

Output: 2

Explanation: You have 2 children and 3 cookies. The greed factors of 2 children are 1, 2.
You have 3 cookies and their sizes are big enough to gratify all of the children,
You need to output 2.
 
class Solution(object):
def findContentChildren(self, g, s):
"""
:type g: List[int]
:type s: List[int]
:rtype: int
"""
giterator=0
siterator=0
count=0
glen=len(g)
slen=len(s)
s=sorted(s)
g=sorted(g) while siterator<slen and giterator<glen:
if g[giterator]<=s[siterator]:
count+=1
giterator+=1
siterator+=1
else:
siterator+=1
return count

  

[LeetCode&Python] Problem 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

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

  3. 455. Assign Cookies - LeetCode

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

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

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

  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 455. Assign Cookies (C++)

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

  8. [leetcode greedy]455. Assign Cookies

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

  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. [LeetCode] 99. Recover Binary Search Tree(复原BST) ☆☆☆☆☆

    Recover Binary Search Tree leetcode java https://leetcode.com/problems/recover-binary-search-tree/di ...

  2. linux basic test

    Linux 1◆ 提供连接     2◆ connection baidu.com 3◆ vm tools install Reboot    

  3. bash 调试

    bashdb test.sh step edit  visual 跳到那一行 R restart http://www.ibm.com/developerworks/cn/linux/l-cn-she ...

  4. web前端开发面试题(答案)

    1.xhtml和html有什么区别? HTML是一种基本的WEB网页设计语言,XHTML是一个基于XML的置标语言最主要的不同:XHTML 元素必须被正确地嵌套.XHTML 元素必须被关闭.标签名必须 ...

  5. sqlcipher 数据库解密

    使用 sqlcipher.exe 可以在输入密码后,查看加密数据库的内容. 但是要编码查询数据库的内容,还要另寻方法.(相关的工具和库在我的百度网盘中) 使用sqlcipher windows 命令工 ...

  6. Consecutive Subsequence CodeForces - 977F(dp)

    Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把 ...

  7. AI的新增功能(定义图案)(描边渐变)(图像描摹)5.1

    1.定义图案:打开一个AI素材文件如图: 选择工具拖拽选择这个图案,选择“对象”“图案”“建立”完成图案的建立 此时会弹出图案选项对话框,改变拼贴类型,图案宽高,份数,不透明度,单击"完成“ ...

  8. information_schema

    views 视图表,查看当前数据库有哪些视图 select table_catalog,table_schema,table_name,is_updatable,definer,security_ty ...

  9. ubuntu下修改MYSQL数据库密码

    在介绍修改密码之前,先介绍一个文件/etc/MySQL/debian.cnf.其主要内容如下图: 里面有一个debian-sys-maint用户,这个用户只有Debian或Ubuntu服务器才有,所以 ...

  10. JavaScript 基础,登录前端验证

    <script></script>的三种用法: 放在<body>中 放在<head>中 放在外部JS文件 <!DOCTYPE html> & ...