반응형
Q. Given the array candies and the integer extraCandies, where candies[i] represents the number of candies that the ith kid has. For each kid check if there is a way to distribute extraCandies among the kids such that he or she can have the greatest number of candies among them. Notice that multiple kids can have the greatest number of candies.
let kidsWithCandies = function(candies, extraCandies) {
let maxCandiesNum = Math.max(...candies);
let boolMaxCandies = candies.map(function(idx){
idx += extraCandies;
if(idx>=maxCandiesNum) return true;
else if(idx<maxCandiesNum) return false;
});
return boolMaxCandies;
};
반응형
'DEVELOP > Algorithm' 카테고리의 다른 글
[leetcode] 1748. Sum of Unique Elements (0) | 2021.02.23 |
---|---|
[leetcode] 1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence (0) | 2021.02.22 |
[leetcode] 1720. Decode XORed Array (0) | 2021.02.22 |