💬 Info
There are n
kids with candies.
You are given an integer array candies
, where each candies[i]
represents the number of candies the 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 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.
n == candies.length
2 <= n <= 100
1 <= candies[i] <= 100
1 <= extraCandies <= 50
풀이 시간 : 12분
candies[i] + extraCandies >= max
조건 만족 시 True 반환import java.util.*;
class Solution {
public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
int max = 0;
for (int candy : candies) {
max = Math.max(max, candy);
}
List<Boolean> result = new ArrayList<>(candies.length);
for (int candy : candies) {
result.add(candy + extraCandies >= max);
}
return result;
}
}