I am trying to improve my linq syntax coding and i was wondering if anyone could show me a better way of writing this code below.Question is taken from leetcode https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/. Thanks
public static IList<bool> KidsWithCandies(int[] candles, int extraCandies)
{
var kidCandle = candles.Select(x => x+ extraCandies);
var con = new List<bool>();
foreach(var kid in kidCandle)
{
if (kid >= candles.Max())
con.Add(true);
else
con.Add(false);
}
return con;
}
https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/
int max = candles.Max(); List<bool> con = candles.Select(x => x + extraCandies>= max).ToList();