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.
class Solution:
def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:
max_nums = max(candies)
result = []
for i in range(len(candies)):
if max_nums - (candies[i] + extraCandies) <= 0:
result.append(True)
else:
result.append(False)
return result
Runtime : 40 ms
class Solution:
def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:
max_num = max(candies)
return [ (candy + extraCandies) >= max_num for candy in candies ]
Runtime : 36 ms