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.

题目冗长,但是主旨十分的简单;就是给两个数组A,B ,找到A中小于等于B元素的最大个数

public int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int num = 0;
for(int i = 0 ; i < s.length; i++)
if(num < g.length)
if(s[i] >= g[num])
num ++;
return num;
}

455. Assign Cookies.md的更多相关文章

  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

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

  3. 455. Assign Cookies - LeetCode

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

  4. 12. leetcode 455.Assign Cookies

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

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

  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. 455. Assign Cookies 满足欲望 分配饼干

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

随机推荐

  1. 在没有DOM操作的日子里,我是怎么熬过来的(上)

    前言 在我动笔写这篇文章的时候,我刚刚从我的项目中删除了最后一行JQuery代码.至于我为何要这么做,请听闰土娓娓道来.前几年我还在想,假如有一天,前端世界里不能再直接操作dom了,我该怎么办?没想到 ...

  2. Shell脚本数据备份

  3. .net 系列:事件和委托

    在.net 的世界里,离不开委托和事件,其实理解透了后很简单,总结了一下分为5步:   1)定义委托   public delegate void RevicedEventHandler(object ...

  4. .net 系列:并发编程之一 并发编程的初步理论

    一.关于并发编程的几个误解 1)并发就是多线程 实际上多线程只是并发编程的一种形式而已,在C#中还有很多其他的并发编程技术,包括异步编程,并行编程,TPL数据流,响应式编程等.  2)只有大型服务器才 ...

  5. TCP/IP协议栈 --- IP路由

    IP路由:当一个IP包在主机发送出去或者在网络当中时,是怎么选择路径到达目的主机的呢? 一般情况下, 如果说源主机和目的主机在同一个网络中的话,那个数据报可以直接到达目的主机而不经过路由器,下面可以试 ...

  6. C#爬虫系列(一)——国家标准全文公开系统

    网上有很多Python爬虫的帖子,不排除很多培训班借着AI的概念教Python,然后爬网页自然是其中的一个大章节,毕竟做算法分析没有大量的数据怎么成. C#相比Python可能笨重了些,但实现简单爬虫 ...

  7. netconf、yang和XML关系

    netconf是基于xml的网络配置协议,文档RFC6241有详细介绍. yang是为netconf建模的一种数据建模语言.文档RFC2060详细介绍了yang1.0版本,RFC7950介绍了yang ...

  8. javascript中break,continue和return语句用法小结:

    Break语句会使程序立刻退出包含在最底层的循环或者退出一个switch语句,它是用来退出循环或者switch语句. 例如: <script type="text/javascript ...

  9. Java数据结构和算法(七)——链表

    前面博客我们在讲解数组中,知道数组作为数据存储结构有一定的缺陷.在无序数组中,搜索性能差,在有序数组中,插入效率又很低,而且这两种数组的删除效率都很低,并且数组在创建后,其大小是固定了,设置的过大会造 ...

  10. post 与get 区别

    刷新/后退按钮 GET后退按钮/刷新无害,POST数据会被重新提交(浏览器应该告知用户数据会被重新提交). 书签 GET书签可收藏,POST为书签不可收藏. 缓存 GET能被缓存 缓存是针对URL来进 ...