본문 바로가기
python-algorithm

leetcode 1431. Kids With the Greatest Number of Candies

by 무적김두칠 2023. 4. 17.

https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/description/

 

Kids With the Greatest Number of Candies - LeetCode

Can you solve this real interview question? Kids With the Greatest Number of Candies - There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith kid has, and an integer extraCandie

leetcode.com

 

1
2
3
4
5
6
7
8
9
10
11
class Solution:
    def kidsWithCandies(self, candies: List[int], extraCandies: int-> List[bool]:
        my_max = max(candies)
        answer = []
        for candy in candies:
            if candy + extraCandies >= my_max:
                answer.append(True)
            else:
                answer.append(False)
 
        return answer
cs
반응형

댓글