1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-12 19:01:47 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/拥有最多糖果的孩子 [kids-with-the-greatest-number-of-candies].html
2025-01-09 20:29:41 +08:00

46 lines
2.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>&nbsp;<code>n</code>&nbsp;个有糖果的孩子。给你一个数组&nbsp;<code>candies</code>,其中&nbsp;<code>candies[i]</code>&nbsp;代表第 <code>i</code> 个孩子拥有的糖果数目,和一个整数&nbsp;<code>extraCandies</code>&nbsp;表示你所有的额外糖果的数量。</p>
<p>返回一个长度为&nbsp;<code>n</code>&nbsp;的布尔数组 <code>result</code>,如果把所有的&nbsp;<code>extraCandies</code>&nbsp;给第&nbsp;<code>i</code>&nbsp;个孩子之后,他会拥有所有孩子中&nbsp;<strong>最多&nbsp;</strong>的糖果,那么&nbsp;<code>result[i]</code>&nbsp;&nbsp;<code>true</code>,否则为 <code>false</code></p>
<p>注意,允许有多个孩子同时拥有 <strong>最多</strong>&nbsp;的糖果数目。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>candies = [2,3,5,1,3], extraCandies = 3
<strong>输出:</strong>[true,true,true,false,true]
<strong>解释:</strong>如果你把额外的糖果全部给:
孩子 1将有 2 + 3 = 5 个糖果,是孩子中最多的。
孩子 2将有 3 + 3 = 6 个糖果,是孩子中最多的。
孩子 3将有 5 + 3 = 8 个糖果,是孩子中最多的。
孩子 4将有 1 + 3 = 4 个糖果,不是孩子中最多的。
孩子 5将有 3 + 3 = 6 个糖果,是孩子中最多的。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>candies = [4,2,1,1,2], extraCandies = 1
<strong>输出:</strong>[true,false,false,false,false]
<strong>解释:</strong>只有 1 个额外糖果,所以不管额外糖果给谁,只有孩子 1 可以成为拥有糖果最多的孩子。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>candies = [12,1,12], extraCandies = 10
<strong>输出:</strong>[true,false,true]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == candies.length</code></li>
<li><code>2 &lt;= n &lt;= 100</code></li>
<li><code>1 &lt;= candies[i] &lt;= 100</code></li>
<li><code>1 &lt;= extraCandies &lt;= 50</code></li>
</ul>