LeetCode:455. Assign Cookies
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的更多相关文章
- LeetCode 455. Assign Cookies (分发曲奇饼干)
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
- 12. leetcode 455.Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
- LeetCode 455. Assign Cookies (C++)
题目: Assume you are an awesome parent and want to give your children some cookies. But, you should gi ...
- LeetCode: 455 Assign Cookies(easy)
题目: Assume you are an awesome parent and want to give your children some cookies. But, you should gi ...
- 【leetcode】455. Assign Cookies
problem 455. Assign Cookies solution1: But, you should give each child at most one cookie. 对小朋友的满意程度 ...
- 455. Assign Cookies - LeetCode
Question 455. Assign Cookies Solution 题目大意:数组g的大小表示有几个小孩,每个元素表示小孩的食量,数组s的大小表示有多少个饼干,每个元素的大小表示每个饼干的大小 ...
- 【LeetCode】455. Assign Cookies 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...
- [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 ...
- [leetcode greedy]455. Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
随机推荐
- CentOS 创建SVN 服务器,并且自动同步到WEB 目录
CentOS 创建SVN 服务器,并且自动同步到WEB 目录 标签: centossvnsubversion服务器 2013-12-06 10:09 5492人阅读 评论(0) 收藏 举报 分类: ...
- 双十二前夕爆京东12G数据泄露的真相是什么
今天早上手机上推送出京东12g数据泄漏的消息,随即搜了下网上的相关新闻,感觉舆论又一次的干了一件惊天地的事情,到底京东的哪所谓的12G的用户信息数据有没有泄漏?舆论为什么齐刷刷的在12月11日突然间爆 ...
- JavaScript自学之数组排序
<html> <head> <title>数组排序</title> <script type="text/javascript" ...
- 关于安装AccessDatabaseEngine_x64.exe 的说明
开始--运行中 输入 cmd 进入界面 再输入路径 E:\BaiduYunDownload\AccessDatabaseEngine_X64.exe /passive 即完成安装. 注意,路 ...
- 神奇的 CURL 命令
CURL? 嗯,说来话长了~~~~ 这东西现在已经是苹果机上内置的命令行工具之一了,可见其魅力之一斑 1) 二话不说,先从这里开始吧! curl http: //www.yahoo.com 回车之 ...
- 数据结构与算法分析——C语言描述 第三章的单链表
数据结构与算法分析--C语言描述 第三章的单链表 很基础的东西.走一遍流程.有人说学编程最简单最笨的方法就是把书上的代码敲一遍.这个我是头文件是照抄的..c源文件自己实现. list.h typede ...
- 点击input时,里面默认字体消失显示
点击input时,点击input里面默认字体消失显示: <input type="" name="" id="" value=&quo ...
- HTTP缓存&代理
一.与缓存有关的Header 1.Request If-Modified-Since: 缓存文件的最后修改时间 If-None-Match: ...
- linux下解压
(1).*.tar 用 tar –xvf 解压 (2).*.gz 用 gzip -d或者gunzip 解压 (3).*.tar.gz和*.tgz 用 tar –xzf 解压 (4).*.bz2 ...
- CSS之viewport 1
在这个迷你系列的文章里边我将会解释viewport,以及许多重要元素的宽度是如何工作的,比如<html>元素,也包括窗口和屏幕. 这篇文章是关于桌面浏览器的,其唯一的目的就是为移动浏览器中 ...