題目會給定一個陣列candies和一個整數extraCandies作為輸入。
陣列candies代表每一位小朋友手上擁有的糖果總數。
問我們,從頭到尾每一位小朋友,如果多給extraCandies顆糖果給其中某一位小朋友,那位小朋友拿到的糖果數量是不是最多的?假如是,則標記為True,假如不是則標記為False。
輸出以boolean陣列的形式返回答案。
Example 1:
Input: candies = [2,3,5,1,3], extraCandies = 3
Output: [true,true,true,false,true]
Explanation: If you give all extraCandies to:
- Kid 1, they will have 2 + 3 = 5 candies, which is the greatest among the kids.
- Kid 2, they will have 3 + 3 = 6 candies, which is the greatest among the kids.
- Kid 3, they will have 5 + 3 = 8 candies, which is the greatest among the kids.
- Kid 4, they will have 1 + 3 = 4 candies, which is not the greatest among the kids.
- Kid 5, they will have 3 + 3 = 6 candies, which is the greatest among the kids.
Example 2:
Input: candies = [4,2,1,1,2], extraCandies = 1
Output: [true,false,false,false,false]
Explanation: There is only 1 extra candy.
Kid 1 will always have the greatest number of candies, even if a different kid is given the extra candy.
Example 3:
Input: candies = [12,1,12], extraCandies = 10
Output: [true,false,true]
Constraints:
n == candies.length
糖果陣列和小朋友的數目一樣長,總共有n位小朋友。
2 <= n <= 100
小朋友的數目介於2~100之間。
1 <= candies[i] <= 100
每一位小朋友初始的糖果數量介於1~100顆糖果。
1 <= extraCandies <= 50
額外多給的糖果參數介於1~50顆之間。
題目要問的核心觀念在於:
額外多給糖果之後,某一位小朋友的糖果數量是不是最多的?
所以,只要先找出原本全體小朋友個別擁有糖果的最大值。