[LeetCode] Kids With the Greatest Number of Candies

題目:Kids With the Greatest Number of Candies
難度:Easy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class Solution {
public IList<bool> KidsWithCandies(int[] candies, int extraCandies) {
// 找出在給 extraCandies 之前,最大的糖果數
var greatestBeforeGiving = candies.ToList().OrderBy(i => i).Last();

var result = new bool[candies.Length];

for (var i = 0; i < candies.Length; i++)
{
result[i] = (candies[i] + extraCandies) >= greatestBeforeGiving ?
true : false;
}

return result;
}
}

Comments