分发饼干
1,讲两个列表排序
2,从最小开始比较
3,如果饼干能够满足小朋友,则列表索引均加一,如果不能满足小朋友,则跳过该饼干,用下一个饼干比较
class Solution(object):
def findContentChildren(self, g, s):
"""
:type g: List[int]
:type s: List[int]
:rtype: int
"""
if not g or not s:
return 0
g.sort()
s.sort()
t = len(s)
k = len(g)
i = 0
j = 0
while i < k and j < t:
while j < t and s[j] < g[i]:
j += 1
if j == t:
return i
else:
i += 1
j += 1
return i