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. BZOJ 4368: [IOI2015]boxes纪念品盒

    三种路径,左边出去左边回来,右边出去右边回来,绕一圈 绕一圈的路径最多出现一次 那么绕一圈的路径覆盖的点一定是左边半圈的右边和右边半圈的左边 枚举绕一圈的路径的起始点(一定要枚举,这一步不能贪心),更 ...

  2. poj2823 Sliding Window luogu1886 滑动窗口 单调队列

    模板题 #include <iostream> #include <cstring> #include <cstdio> using namespace std; ...

  3. luogu1251 餐巾计划问题

    ss是源点,代表餐巾卖家,tt是汇点,代表记账收钱者. 记p(i)是i天早晨的可用毛巾数,q(i)是i天完了的废毛巾数. 建图见注释 #include <iostream> #includ ...

  4. CornerStone使用教程(配置SVN,HTTP及svn简单使用)

    1.SVN配置 假设你公司svn地址为:svn://192.168.1.111/svn/ios,用户名:svnserver,密码:123456 1:填写主机地址 2:如果你的主机地址中有端口号,如为1 ...

  5. AtCoder Beginner Contest 070

    我好想有点思维江化,所以我想给这个丝毫没有问题的abc也写下 A - Palindromic Number Time Limit: 2 sec / Memory Limit: 256 MB Score ...

  6. centos7下nginx添加到自定义系统服务中提示Access denied

    安装好nginx后,添加到系统服务中 在/usr/lib/systemd/system下创建nginx.service文件内容如下: [Unit] Description=nginx - high p ...

  7. 【mysql优化 3】嵌套循环连接算法

    原文地址:Nested-Loop Join Algorithms mysql在表之间执行连接操作,包括了使用循环嵌套算法或者其他在此基础上的变形. 循环嵌套连接算法: 一个简单的嵌套循环连接(NLJ: ...

  8. PHP杂技(一)

    逻辑运算符 &&和& ||和|的部分区别 返回结果类型不同, A||B 如果A为真那么B不会做判断,而A|B前后都做判断 switch判断中并不是===,更像是==,例如(1) ...

  9. 让Android软键盘默认进入英文键盘

    今天在做一个功能的 时候,需要输入法软键盘弹出后,需要进入英文输入界面. 可以通过设置EditText的输入类型为EMAIL来实现.     //将输入法切换到英文     edit.setInput ...

  10. iOS学习笔记46-Swift(六)扩展

    一.Swift扩展 扩展就是向一个已有的类.结构体或枚举类型添加新功能,这包括在没有权限获取原始源代码的情况下扩展类型的能力.扩展和 Objective-C中的分类(category)类似,但是它要比 ...