Easy
,Array
1431. Kids With the Greatest Number of Candies
There are n
kids with candies. You are given an integer array candies
, where each candies[i]
represents the number of candies the ith kid has, and an integer extraCandies
, denoting the number of extra candies that you have.
Return a boolean array result
of length n
, where result[i]
is true
if, after giving the ith kid all the extraCandies
, they will have the greatest number of candies among all the kids, or false
otherwise.
Note that multiple kids can have the greatest number of candies.
Example 1:
Example 2:
Example 3:
Constraints:
n
== candies.length
n
<= 100candies[i]
<= 100extraCandies
<= 50Ron ChenMon, Apr 17, 2023
gpwork4uMon, Apr 17, 2023
就不能貪心一點,一行跟速度都要嗎?
Yen-Chi ChenMon, Apr 17, 2023
MarsgoatMon, Apr 17, 2023
學習樓上,這樣寫beat99%
MarsgoatMon, Apr 17, 2023
當傳入的 numeric array 非常大的時候,可以使用Array.reduce()
SheepMon, Apr 17, 2023
練習一下 Java 8 Stream API
Ron ChenTue, Apr 18, 2023