455. Assign Cookies

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.

假设你是一个很棒的父母,并想给你的孩子一些饼干。但是,你应该给每个孩子一个饼干。每个孩子我都有一个贪婪因子gi,这是孩子满意的cookie的最小尺寸;每个cookie j的大小为sj。如果sj> = gi,我们可以将cookie j分配给孩子i,而孩子i将满足。您的目标是最大化内容子项的数量并输出最大数量。

Note: You may assume the greed factor is always positive. You cannot assign more than one cookie to one child.

你可能认为贪婪因子总是积极的。 您不能为一个孩子分配多个cookie。

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.
您有3个孩子和2个cookie。 3个孩子的贪婪因素是1,2,3。
即使你有2个饼干,因为它们的大小都是1,你只能让孩子的贪心因子是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.
您有2个孩子和3个cookie。 2个孩子的贪婪因素是1,2。
你有3个饼干,它们的大小足以满足所有孩子,
你需要输出2。

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦