package Others;

 import java.util.Arrays;

 //Question 455. Assign Cookies
/*
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.
*/
public class findContentChildren455 {
public static int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int i=0;
for(int j=0;i<g.length&&j<s.length;j++){
if(g[i]<=s[j]){
i++;
}
}
return i;
}
public static void main(String[] arg){
int[] g={1,2};
int[] s={1,1};
System.out.println(findContentChildren(g,s));
}
}

LeetCode:455. Assign Cookies的更多相关文章

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

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

  2. 12. 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. Struts2 OGNL 字符串自定义转化对象细节

    要使用Struts2的自定义对象转化,需要几个要点: 1.要有继承DefaultTypeConverter的实现类,要重写convertValue,并且参数value转化而来的String是Strin ...

  2. Windows下wnmp相关配置

    #wnmp mysqld -install net start mysql memcached -d uninstall memcached -d install net start memcache ...

  3. ASP.NET Core 添加日志NLog

    1.在Nuget上搜索 NLog.Extensions.Logging 安装最新版 2.添加日志配置文件,在项目指定目录下添加配置文件nlog.config,内容添加如下: <?xml vers ...

  4. HTML中添加背景音乐

    <audio controls="controls" height="100" width="100"> <source ...

  5. 通过href简单实现单击a链接跳转到页面指定位置

    在页面中点击a标签后,要使其跳到页面里面相应的地方,方法很简单,就是在a标签里面href中的内容和你要跳到这个区域的id同名即可,例如: <a href="#ppp" tar ...

  6. java测试框架整理

    Test: Junit4+Hamcrest 不多说了,就靠着两个 import static org.hamcrest.Matchers.equalTo; import static org.juni ...

  7. Uiautomator ——API详解(转载http://www.cnblogs.com/by-dream/p/4921701.html)

    转载来源: 简单的例子 以一个简单的例子开始吧.我们完成一个 " 打开QQ,进入QQ空间,然后退出 " 的case. 代码如下: package QQ; import java.i ...

  8. Sublime Text3 以及 SublimeREPL使用Virtualenv执行python

    1. SublimeText3 安装Virtualenv插件(Crtl+Shift+P) 2. 新建python虚拟环境: Crtl+Shift+P,选中Virtualenv:New选项,在底部Vir ...

  9. 如何用jenkins实现自动化构建新版本和二维码下载

    最近公司开发了自己的app,研发过程中对于测试人员来说,经常会像开发的人员询问,有没有最新的包啊(apk打包后的新版本),以免你测试的时候,提交了一些缺陷,实际上人家已经解决了.当然你也可以说你们公司 ...

  10. kali 下文件操作

    记得看到一片文章中说要学习linux 不要用kali.. 不感兴趣的东西,还指望我去搞个Ubuntu.... Ctrl+I 清屏 CD命令: cd 进入用户主目录: cd ~ 进入用户主目录: cd ...