LeetCode_455. Assign Cookies
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.
package leetcode.easy;
public class AssignCookies {
public int findContentChildren(int[] g, int[] s) {
java.util.Arrays.sort(g);
java.util.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;
}
@org.junit.Test
public void test() {
int[] g1 = { 1, 2, 3 };
int[] s1 = { 1, 1 };
int[] g2 = { 1, 2 };
int[] s2 = { 1, 2, 3 };
System.out.println(findContentChildren(g1, s1));
System.out.println(findContentChildren(g2, s2));
}
}
LeetCode_455. Assign Cookies的更多相关文章
- 【leetcode】455. Assign Cookies
problem 455. Assign Cookies solution1: But, you should give each child at most one cookie. 对小朋友的满意程度 ...
- LeetCode:455. Assign Cookies
package Others; import java.util.Arrays; //Question 455. Assign Cookies /* Assume you are an awesome ...
- 455. Assign Cookies - LeetCode
Question 455. Assign Cookies Solution 题目大意:数组g的大小表示有几个小孩,每个元素表示小孩的食量,数组s的大小表示有多少个饼干,每个元素的大小表示每个饼干的大小 ...
- [LeetCode] Assign Cookies 分点心
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
- Leetcode: 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 (分发曲奇饼干)
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
- 455. Assign Cookies.md
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
- [Swift]LeetCode455. 分发饼干 | Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
随机推荐
- 2019年杭电多校第二场 1008题Harmonious Army(HDU6598+最小割+建图)
题目链接 传送门 题意 有\(n\)个士兵,要你给他们分配职业.有\(m\)对关系,对于某一对关系\(u,v\),如果同为勇士则总能力增加\(a\),同法师则增加\(c\),一个勇士一个法师增加\(\ ...
- 201671010442 葸铃 实验十四 团队项目评审&课程学习总结
项目 内容 这个作业属于哪个课程 课程 2016级计算机科学与工程学院软件工程(西北师范大学) 作业要求 实验十四 团队项目评审&课程学习总结 作业学习目标 团队项目评审&课程学习总结 ...
- vim 常用命令(记录)
很好的vim讲解:https://blog.csdn.net/weixin_37657720/article/details/80645991 命令模式:默认模式.输入ctrl+c, 输入:,转换为命 ...
- linux 用户操作命令
今日思语:看到优秀的人还那么努力,你是否会眼馋~ linux系统上经常会对用户进行一些相关操作,像新增.修改.删除用户等操作. 1.新增用户 useradd 选项 用户 参数说明: • 选项: • - ...
- windows 命令
1.查看端口占用: netstat -ano|findstr 8080 2.查看网络端口:ipconfig/all
- ent 基本使用十一 sql.DB 集成
这个功能是github中大家提的比较多的一个,所以官方也暴露了相关的api 配置sql.DB 一种方式 package main import ( "time" " ...
- 使用nodegui 开发高性能的跨平台桌面端应用
nodegui 是基于qt + nodejs 的跨平台桌面开发方案,官方同时也提供了很不错的文档 简单使用 使用官方的starter clone 代码 git clone https://github ...
- 【题解】洛谷 P2725 邮票 Stamps
目录 题目 思路 \(Code\) 题目 P2725 邮票 Stamps 思路 \(\texttt{dp}\).\(\texttt{dp[i]}\)表示拼出邮资\(i\)最少需要几张邮票. 状态转移方 ...
- 自建 ca 及使用 ca 颁发证书
创建CA: 一.安装openssl [root@localhost ~]# yum install -y openssl 二.创建CA的相关文件及目录 mkdir /opt/root_ca & ...
- GET /static/css/bootstrap.min.css.map HTTP/1.1" 404
解决办法:删除bootstrap.min.css文件内容最后一行/*…………*/内容即可