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的更多相关文章

  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. LeetCode_455. Assign Cookies

    455. Assign Cookies Easy Assume you are an awesome parent and want to give your children some cookie ...

  4. 455. Assign Cookies - LeetCode

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

  5. [LeetCode] Assign Cookies 分点心

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

  6. Leetcode: Assign Cookies

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

  7. 12. leetcode 455.Assign Cookies

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

  8. LeetCode 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.md

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

  10. [Swift]LeetCode455. 分发饼干 | Assign Cookies

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

随机推荐

  1. Django基于Pycharm开发之一【创建django工程】

    Django的工程结构,可以通过pycharm里面,选择创建django工程来直接创建,也可以通过命令行通过pip来安装. 一.通过命令行安装的步骤 Install Python. Install a ...

  2. oracle整体结构-内存结构、物理结构、逻辑结构、进程

    Oracle的体系结构大体上分为两部分:Instance(实例)和Database(数据库). Instance(实例) :在Oracle Instance中主要包含了SGA以及一些进程(例如:PMO ...

  3. 再谈H2的MVStore与MVMap

    对H2的[MVStore]: http://www.cnblogs.com/simoncook/p/5188105.html 这篇文章的补充. 概述 我们通常用的map,比如HashMap Linke ...

  4. python - work4

    # -*- coding:utf-8 -*- '''@project: jiaxy@author: Jimmy@file: work_20181108.py@ide: PyCharm Communit ...

  5. Educational Codeforces Round 20 A. Maximal Binary Matrix

    A. Maximal Binary Matrix time limit per test 1 second memory limit per test 256 megabytes input stan ...

  6. centos7 install google-chrome

    important: Google Chrome support for all 32-bit Linux distributions is deprecated from March, 2016. ...

  7. java EE技术体系——CLF平台API开发注意事项(2)——后端测试

    前言:上篇博客说到了关于开发中的一些情况,这篇博客主要说明一些关于测试的内容. 一.宏观说明 要求:每一个API都必须经过测试.   备注:如果涉及到服务间调用(如权限和基础数据),而对方服务不可用时 ...

  8. 基于RESTful 的几种实现(就随便了解一下)

    百度来的,原文未标出处,侵删. 1.1. RailsRuby on Rails是新兴的敏捷Web开发框架,在动态语言Ruby的支持下,Rails以新鲜的视角告诉我们Web开发是简单而快乐的.Rails ...

  9. [USACO Section 2.1]城堡 The Castle (搜索)

    题目链接 Solution 比较恶心的搜索,思路很简单,直接广搜找联通块即可. 但是细节很多,要注意的地方很多.所以直接看代码吧... Code #include<bits/stdc++.h&g ...

  10. [TJOI2018] Xor 异或 (可持久化Trie,树链剖分)

    题目描述 现在有一颗以 1 为根节点的由 n 个节点组成的树,树上每个节点上都有一个权值 \(v_i\).现在有 Q 次操作,操作如下: 1 x y :查询节点 x 的子树中与 y 异或结果的最大值. ...