455. Assign Cookies
static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
int findContentChildren(vector<int>& g, vector<int>& s)
{
int szchild=g.size();
int szcookies=s.size();
if(szchild==||szcookies==)
return ;
sort(g.begin(),g.end());
sort(s.begin(),s.end());
int indexchild=,indexcookies=;
int count=;
while(indexchild<szchild&&indexcookies<szcookies)
{
if(s[indexcookies]>=g[indexchild])
{
count++;
indexcookies++;
indexchild++;
}
else
indexcookies++;
}
return count;
}
};
排个序,俩数组元素扫描比较即可。
455. 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. 对小朋友的满意程度 ...
- 455. Assign Cookies - LeetCode
Question 455. Assign Cookies Solution 题目大意:数组g的大小表示有几个小孩,每个元素表示小孩的食量,数组s的大小表示有多少个饼干,每个元素的大小表示每个饼干的大小 ...
- 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 ...
- [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 455. Assign Cookies (C++)
题目: Assume you are an awesome parent and want to give your children some cookies. But, you should gi ...
- [leetcode greedy]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 满足欲望 分配饼干
[抄题]: Assume you are an awesome parent and want to give your children some cookies. But, you should ...
随机推荐
- test20181024 kun
题意 分析 考场做法 任意状态只有两种决策,进栈或出栈. 由于元素互不相同,所以选择的关键在于栈顶元素是否在它和带插入元素组成的集合中是最大的. 用stack和set维护.时间复杂度\(O(n \lo ...
- maven库 mvn依赖
http://maven.outofmemory.cn/ http://mvnrepository.com/ 先执行 mvn clean 然后执行 mvn 命令 如:mvn compile . ...
- emacs之配置自动安装脚本
emacsConfig下建立install目录,结构大概这样 . ├── auto-complete-etags-setting.el ├── auto-complete-setting.el ├── ...
- 安装memcached服务 和 php 安装memcache扩展
这是所有的命令,至于哪个命令是干嘛的自己悟去吧 ,顺便穿插一些知识点 安装libevent cd /home/ wget http://www.monkey.org/~provos/libeven ...
- Spark在Windows下的环境搭建
本文转载自:http://blog.csdn.net/u011513853/article/details/52865076 由于Spark是用Scala来写的,所以Spark对Scala肯定是原生态 ...
- java基础-Map的静态初始化以及Map的遍历等.....................
1.map的静态初始化,以及map遍历的几种方法: package com.cy.test; import java.util.HashMap; import java.util.Iterator; ...
- Javascript继承机制的设计思想
转自:http://www.ruanyifeng.com/blog/2011/06/designing_ideas_of_inheritance_mechanism_in_javascript.htm ...
- ACM刷题踩坑记录
2017-12-26: 1.再次被写法坑了好长一会,调了半天的bug,还是没找出来.最后,发现,又坑在这个小细节上了.这样子写,第一个if和第三个else在一次循环中都会执行,然后,就GG了. 要注意 ...
- 好记性比如烂笔头--linux学习笔记7关于linux中的shell脚本编程
之前看的各种面试,貌似都有shell脚本编程,没了解之前感觉很复杂,现在了解了些,没想象中那么难. 逻辑主要是这样的 编写.sh的脚本文件,文件里面的代码,就是在命令行输入的可执行命令的加强版,所谓加 ...
- np归纳总结(全)第一天
1.概述 1.np.array() # 将列表转换为数组 import numpy as np array = [1, 2, 3, 4, 5] array = np.array(array) 2.. ...