Problem solving/Algorithms

[LeetCode] 1431. Kids With the Greatest Number of Candies (Python)

Young_A 2021. 1. 9. 14:28

LeetCode - Problems - Algorithms - 1431. Kids With the Greatest Number of Candies

Problem Description

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.

 

Example:

Constraints:

My Solution (Python)

class Solution:
    def kidsWithCandies(self, candies, extraCandies):
        Maximum_Candies = max(candies)
        answers = []
        for c in candies:
            if c + extraCandies >= Maximum_Candies:
                answers.append(True)
            else:
                answers.append(False)
        return answers