# 0455-分发饼干(0455 – distribution of biscuits)-其他

## 0455-分发饼干(0455 – distribution of biscuits)

1 <= g.length <= 3 * 104
0 <= s.length <= 3 * 104
1 <= g[i], s[j] <= 231 – 1

### python

``````# 0455.分发饼干

class Solution1:
def findContentChildren(self, g:[int], s:[int]) -> int:
"""
小饼干优先喂饱小胃口
:param g:
:param s:
:return:
"""
g.sort() # 小孩胃口排序
s.sort() # 饼干尺寸排序
res = 0
for i in range(len(s)):
if res < len(g) and s[i] >= g[res]: # 小饼干优先喂饱小胃口
res += 1
return res

class Solution2:
def findContentChildren(self, g:[int], s:[int]) -> int:
"""
大饼干优先喂饱大胃口
:param g:
:param s:
:return:
"""
g.sort() # 小孩胃口排序
s.sort() # 饼干尺寸排序
start, count = len(s)-1, 0
for index in range(len(g)-1, -1, -1):
if start >= 0 and g[index] <= s[start]:
start -= 1
count += 1
return count
``````

### golang

``````package greedy

import "sort"

// 小饼干满足小胃口
func findContentChildren1(g,s []int) int {
sort.Ints(g)
sort.Ints(s)
var res int = 0
for i:=0;i<len(s);i++ {
if res < len(g) && s[i] >= g[res] {
res++
}
}
return res
}

// 大饼干优先满足大胃口
func findContentChildren2(g,s []int) int {
sort.Ints(g)
sort.Ints(s)
start, count := len(s)-1, 0
for index:=len(g)-1;index>-1;index-- {
if start >= 0 && g[index] <= s[start] {
start--
count++
}
}
return count
}
``````
————————

Suppose you are a great parent and want to give your children some cookies. However, each child can only give one biscuit at most.

For every child I, there is an appetite value   G [i], this is the minimum size of biscuits that can satisfy children’s appetite; And every cookie J has a size s [J]  。 If s [J]  & gt;= G [i], we can distribute this biscuit J to child I, and the child will be satisfied. Your goal is to meet as many children as possible and output this maximum value.

Example   1:

Input: g = [1,2,3], s = [1,1]
Output: 1
Explanation:
You have three children and two biscuits. The appetite values of the three children are: 1, 2 and 3.
Although you have two small biscuits, because their size is 1, you can only satisfy children with an appetite of 1.
So you should output 1.
Example   2:

Input: g = [1,2], s = [1,2,3]
Output: 2
Explanation:
You have two children and three cookies. The appetite values of two children are 1 and 2 respectively.
You have enough cookies and sizes to satisfy all children.
So you should output 2

Tips:

1 <= g.length <= 3 * 104
0 <= s.length <= 3 * 104
1 <= g[i], s[j] <=   231 – 1

reference resources:

### python

``````# 0455.分发饼干

class Solution1:
def findContentChildren(self, g:[int], s:[int]) -> int:
"""
小饼干优先喂饱小胃口
:param g:
:param s:
:return:
"""
g.sort() # 小孩胃口排序
s.sort() # 饼干尺寸排序
res = 0
for i in range(len(s)):
if res < len(g) and s[i] >= g[res]: # 小饼干优先喂饱小胃口
res += 1
return res

class Solution2:
def findContentChildren(self, g:[int], s:[int]) -> int:
"""
大饼干优先喂饱大胃口
:param g:
:param s:
:return:
"""
g.sort() # 小孩胃口排序
s.sort() # 饼干尺寸排序
start, count = len(s)-1, 0
for index in range(len(g)-1, -1, -1):
if start >= 0 and g[index] <= s[start]:
start -= 1
count += 1
return count
``````

### golang

``````package greedy

import "sort"

// 小饼干满足小胃口
func findContentChildren1(g,s []int) int {
sort.Ints(g)
sort.Ints(s)
var res int = 0
for i:=0;i<len(s);i++ {
if res < len(g) && s[i] >= g[res] {
res++
}
}
return res
}

// 大饼干优先满足大胃口
func findContentChildren2(g,s []int) int {
sort.Ints(g)
sort.Ints(s)
start, count := len(s)-1, 0
for index:=len(g)-1;index>-1;index-- {
if start >= 0 && g[index] <= s[start] {
start--
count++
}
}
return count
}
``````