1431. Kids With the Greatest Number of Candies

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.

先求最大值,然后判断每个值+extra和最大值的关系

class Solution(object):
    def kidsWithCandies(self, candies, extraCandies):
        """
        :type candies: List[int]
        :type extraCandies: int
        :rtype: List[bool]
        """
        max_value = max(candies)
        ans = []
        for value in candies:
            if value + extraCandies >= max_value:
                ans.append(True)
            else:
                ans.append(False)
        return ans
原文地址:https://www.cnblogs.com/whatyouthink/p/13205079.html