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.

思路:由于一个孩子只能给一个,所以先把两个数组分别排序,然后逐个比对。

12. leetcode 455.Assign Cookies的更多相关文章

  1. LeetCode:455. Assign Cookies

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

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

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

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

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

  4. LeetCode: 455 Assign Cookies(easy)

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

  5. 【leetcode】455. Assign Cookies

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

  6. 455. Assign Cookies - LeetCode

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

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

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

  8. [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 ...

  9. [leetcode greedy]455. Assign Cookies

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

随机推荐

  1. Laravel踩坑笔记——illuminate/html被抛弃

    起因 在使用如下代码的时候发生报错 {!! Form::open() !!} 错误信息 [Symfony\Component\Debug\Exception\FatalErrorException] ...

  2. .net 4.0 中的特性总结(五):并行编程

    1.任务并行库 从 .NET Framework 4 开始,TPL 是编写多线程代码和并行代码的首选方法. 但是,并不是所有代码都适合并行化:例如,如果某个循环在每次迭代时只执行少量工作,或它在很多次 ...

  3. MongoDB 3.4版本, C# 驱动 2.4 操作

    private static string _connStr = "mongodb://127.0.0.1:27017"; private static string _dbNam ...

  4. 二叉树问题(区间DP好题)

    二叉树问题 时间限制: 1 Sec  内存限制: 128 MB 题目描述 Petya Bulochkin很幸运:他得到了一份在"Macrohard"公司的工作.他想要展现他的才华, ...

  5. 针对Oracle数据库表中的数据的常见操作

    1.查询表中所有数据 select * from 表名; 例:select * from stu; 2.查询的同时修改表中数据 select * from 表名  for update; 例:sele ...

  6. 二维码生成api

    <img id='qrcode_img' src='http://qr.liantu.com/api.php?text={$wenzi}&w={$width}' /> http:/ ...

  7. 【从零开始】用node搭建一个jsonp&json服务

    目录: 一.介绍 二.node安装 三.webstorm配置node环境 四.代码介绍 五.如何使用 六.自定义域名 七.其他 一.介绍 1.背景     日常工作中,跟后端商定好接口格式后:通常采用 ...

  8. 【LeetCode】49. Group Anagrams

    题目: Given an array of strings, group anagrams together. For example, given: ["eat", " ...

  9. Cmake新手使用日记(1)【C++11下的初体验】

    第一次使用Cmake,搜索了很多使用教程,包括<Cmake实践>.<Cmake手册>等,但是在针对最新的C++11条件下编程还是会存在一点点问题,需要实验很多次错误并搜索大量文 ...

  10. JS中关于clientWidth offsetWidth scrollWidth 的区别及意义

    网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...