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.
 
class Solution(object):
def findContentChildren(self, g, s):
"""
:type g: List[int]
:type s: List[int]
:rtype: int
"""
giterator=0
siterator=0
count=0
glen=len(g)
slen=len(s)
s=sorted(s)
g=sorted(g) while siterator<slen and giterator<glen:
if g[giterator]<=s[siterator]:
count+=1
giterator+=1
siterator+=1
else:
siterator+=1
return count

[LeetCode&Python] Problem 455. Assign Cookies More articles about

  1. 【leetcode】455. Assign Cookies

    problem 455. Assign Cookies solution1: But, you should give each child at most one cookie. Satisfaction with children ...

  2. LeetCode:455. Assign Cookies

    package Others; import java.util.Arrays; //Question 455. Assign Cookies /* Assume you are an awesome ...

  3. LeetCode 455. Assign Cookies ( Distribute cookies )

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

  4. 12. leetcode 455.Assign Cookies

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

  5. LeetCode 455. Assign Cookies (C++)

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

  6. [leetcode greedy]455. Assign Cookies

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

  7. LeetCode: 455 Assign Cookies(easy)

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

  8. 455. Assign Cookies.md

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

  9. 455. Assign Cookies Satisfy desire Distribute biscuits

    [ Copy questions ]: Assume you are an awesome parent and want to give your children some cookies. But, you should ...

Random recommendation

  1. C/C++ Practice notes 006

    Characters and string characters follow %d, Print ASCCII Character press %c, Print the character itself ‘0’ 0 ‘\0’ difference : char ch3=0; The equal sign will automatically convert , convert to ASCCII The character corresponding to the value . namely null or \0C String cannot be straight ...

  2. Centos4.3 install MySQL-python-1.2.3, appear error: command &#39;gcc&#39; failed with exit status 1

    stay Linux Centos 4.3 Installation on MySQL-python-1.2.3 when error: command 'gcc' failed with exit status 1, The specific reason is that there is no ...

  3. git Version history

    edition :git rev-parse --git-dir Show Git The location of the repository   --show-cdup Displays the depth of the current workspace Directory  --parseopt Parsing command line arguments $ git rev-parse - ...

  4. linux curses function library

    fedora20, install yum install ncurses-devel Compile time :-lncurses The header file :#include<curses.h> Reference resources :man ncurses \linu ...

  5. MySql Learning notes ( Reprint )

    .  value type -- a.  integer  ----------      type              byte          Range ( Signed bit )     tinyint        1 byte     - ~        ...

  6. jquery $.each and for How to get out of the loop

    jquery $.each and for How to get out of the loop 1.for In the loop we use continue: Terminate this cycle and count into the next cycle , Use break End the whole cycle .2. And in the jquery in $.each The corresponding use r ...

  7. Graduation project ——Django Mail sending function and problem record

    django Send E-mail :send_mail()&send_mass_mail() Self improvement school Liu Jiang's blog HTTPS,TLS and SSL django Sending email and related issues step : 0. Log in as send ...

  8. JAVA Dynamic proxy and method interception ( Use CGLib Realization AOP、 Method intercept 、 entrust )

    AOP use CGLib Easier . More controllable . The implementation of dynamic proxy is very elegant . Entity class : public class SampleClass { public String MyFunction1(String inpu ...

  9. error &quot;OPatch cannot find a valid oraInst.loc file to locate Central Inventory

    Error tersebut terjadi ketika akan menjalankan command opatch lsinventory untuk mengetahui patch yan ...

  10. It's very humorous to explain six kinds of Socket IO Model

    It's very humorous to explain six kinds of Socket IO Model   This paper briefly introduces the current Windows Various supported Socket I/O Model , If you find any mistakes, please let me know . One :select Model two :WSAAsyncSelect ...