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. css透明度的设置

    Css代码 .transparent_class { filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: ...

  2. java http请求,字节流获取百度数据

    请求的地址为: http://api.map.baidu.com/place/v2/search?&q=%E9%A5%AD%E5%BA%97&region=%E9%87%8D%E5%B ...

  3. 长沙JavaEE培训机构哪家比较靠谱?Java培训的职业前景

    长沙JavaEE培训机构哪家比较靠谱?可信度高? 全球信息化的时代已经到来,IT行业越来越受大众的欢迎,所以越来越多的人把注意力集中到IT职业教育培训.在软件开发领域,Java培训已经成为人们的首选, ...

  4. java 获得当前时间 年月日时分秒 星期几

    <%SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");//设置日期格式SimpleDat ...

  5. 【LeetCode】67. Add Binary

    题目: Given two binary strings, return their sum (also a binary string). For example,a = "11" ...

  6. 霍尔开关MH253ESO在减压神器指尖手指陀螺中的作用

    手指陀螺首先在欧美国家流行起来,现如今又在国外掀起一帆狂潮,它是一款排遣无聊的小玩具,又被称为减压神器. 其工作原理:是由一个双向的对称体作为主体,在主体中间嵌入一个轴承的设计组合,整体构成一个可平面 ...

  7. 使用jQuery操作 DOM

    DOM操作分为三类: 1.DOM Core:任何一种支持DOM的编程语言都可以使用它,如getElementById() 2.HTML-DOM:用于处理HTML文档,如document.forms 3 ...

  8. VB6之SendMessage模拟拖放事件

    原文链接:http://hi.baidu.com/coo_boi/item/e1e0f5ab45bddbdd5af191df 网上找了个C++的翻一下,原文链接:http://www.cnblogs. ...

  9. (转载)Oracle10g 数据泵导出命令 expdp 使用总结(二)

    原文链接:http://hi.baidu.com/edeed/item/2c454cff5c559f773d198b94 Oracle10g 数据泵导出命令 expdp 使用总结(一) 1.1.2 e ...

  10. ReOut

    package JBJADV003;import java.io.*;public class ReOut { /** * @param args */ public static void main ...