[力扣] 算法 1431 (C#)

1431. 拥有最多糖果的孩子

public class Solution {
    public IList<bool> KidsWithCandies(int[] candies, int extraCandies) {
        var max = candies[0];
        foreach (var candy in candies.AsSpan(1))
            if (candy > max) max = candy;
        var ret = new bool[candies.Length];
        for(var i = 0; i < candies.Length; i++)
            ret[i] = candies[i] + extraCandies >= max;
        return ret;
    }
}

发表评论