[Leetcode]1431. Kids With the Greatest Number of Candies
2024. 7. 25. 11:47ㆍAlgorithm
1. 문제 :
2. 풀이 :
class Solution:
def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:
if not candies:
return []
max_candies = max(candies)
for i in range(len(candies)):
if candies[i] + extraCandies >= max_candies:
candies[i] = True
else:
candies[i] = False
return candies
max()라는 method를 이용해서 최대 캔디 수를 구한다. 이제 loop를 돌면서 extra candy + current_candy 가 max candy보다 크거나 같은지를 판단하고 맞다면 candies [i]를 True로 아니라면 False로 설정한다.
'Algorithm' 카테고리의 다른 글
[Leetcode]345. Reverse Vowels of a String (0) | 2024.07.26 |
---|---|
[Leetcode]605. Can Place Flowers (0) | 2024.07.25 |
[Leetcode]894. All Possible Full Binary Trees (0) | 2024.07.25 |
[Leetcode]2191. Sort the Jumbled Numbers (3) | 2024.07.24 |
[Leetcode]1071. Greatest Common Divisor of Strings (2) | 2024.07.24 |