
class Solution(object):
def findContentChildren(self, g, s):
"""
:type g: List[int]
:type s: List[int]
:rtype: int
"""
max_nums = 0
g.sort()
s.sort()
i = 0
j = 0
len_g = len(g)
len_s = len(s)
while i < len_g and j < len_s:
if g[i] <= s[j]:
max_nums += 1
i += 1
j += 1
else:
j += 1
return max_nums
本文探讨了如何解决糖果分配问题,通过将儿童对糖果的需求和糖果包的大小进行排序,实现了最大化的满足度。使用Python类和方法,详细解释了算法的实现过程,包括需求和供给的匹配策略。
214

被折叠的 条评论
为什么被折叠?



