assign-cookies
https://leetcode.com/problems/assign-cookies/
用贪心算法即可。
package com.company; import java.util.Arrays;
import java.util.HashMap;
import java.util.Map; class Solution {
public int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int i=, j=;
for (; i<g.length; i++) {
while (j < s.length && g[i] > s[j]) {
j++;
}
if (j == s.length) {
break;
}
j++;
}
return i;
}
} public class Main { public static void main(String[] args) throws InterruptedException { System.out.println("Hello!");
Solution solution = new Solution(); // Your Codec object will be instantiated and called as such:
int[] g = {, , };
int[] s = {};
int ret = solution.findContentChildren(g, s);
System.out.printf("ret:%d\n", ret); System.out.println(); } }
assign-cookies的更多相关文章
- LeetCode:455. Assign Cookies
package Others; import java.util.Arrays; //Question 455. Assign Cookies /* Assume you are an awesome ...
- 【leetcode】455. Assign Cookies
problem 455. Assign Cookies solution1: But, you should give each child at most one cookie. 对小朋友的满意程度 ...
- LeetCode_455. Assign Cookies
455. Assign Cookies Easy Assume you are an awesome parent and want to give your children some cookie ...
- 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 ...
随机推荐
- 《Scrum实战》第2次课【取得大家的支持】课后作业汇总
作业:<变革之心>读后感 孟帅: 2017-7-12http://www.cnblogs.com/mengshuai1982/p/7153985.html
- C++智能指针实现
#include <iostream> #include <string> #define unsigned int size_t using namespace std; / ...
- 大数据学习——sparkSql对接hive
1. 安装mysql 2. 上传.解压.重命名 2.1. 上传 在随便一台有hadoop环境的机器上上传安装文件 su - hadoop rz –y 2.2. 解压 解压缩:apache- ...
- python学习--同目录下调用 (*.py)及不同目录下调(*.py)
注:__init__.py 内容为空 1. 同目录下调用 (Contract_Statelog.py) 如图: temp1.py 调用 Contract_Statelog.py中的方法 2. 不同目 ...
- Codeforces Round #410 (Div. 2) B. Mike and strings
B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- hive查询语法
1.创建表: >create table value_data(citing INT,cited INT) >row format delimited >fields termina ...
- 【Luogu】P3704数字表格(莫比乌斯反演+大胆暴力)
题目链接 给你们讲个笑话:Konoset是个sb,他快速幂的时候把幂次取模了. 原式差不多就是这样吧$\prod\limits_{i=1}^{n}\prod\limits_{j=1}^{m}f[gcd ...
- Node.js 文件输入
最近在尝试用 JavaScript (Node.js) 写题.为此,特地看了 ECMAScript 2017 Language Specification(大雾).写题一般是从文件输入,确切地说是,将 ...
- [LOJ#531]「LibreOJ β Round #5」游戏
[LOJ#531]「LibreOJ β Round #5」游戏 试题描述 LCR 三分钟就解决了问题,她自信地输入了结果-- > -- 正在检查程序 -- > -- 检查通过,正在评估智商 ...
- BZOJ 3786 星系探索 ——Splay
子树可以移动,唔. 还是用Splay维护DFS序即可. 子树的话直接截取出来就好了. 然后求前驱后继可能麻烦一些. 添加两个虚拟节点会比较好写. #include <map> #inclu ...