[LeetCode] 1431. Kids With the Greatest Number of Candies
Updated:
Kids With the Greatest Number of Candies
κ°μ μ΄λ¦°μ΄λ€μ΄ κ°μ§ μ¬ν κ°μμ μΆκ° μ¬ν κ°μλ₯Ό λν΄ μ΄λ¦°μ΄λ€ μ€μ κ°μ₯ λ§μ΄ μ¬νμ κ°μ§κ³ μμΌλ©΄ True λ₯Ό λ°ννλ€.
μ²μμ μΆκ° μ¬ν κ°μλ₯Ό λν λ€ κ·Έ λ μ¬ν λ°°μ΄μμ max κ°μ μ°Ύμ λ°ννλ μμΌλ‘ μ½λ©μ νλ€.
κ·Έλ¦¬κ³ μ μΆμ ν΄λ³΄λ.. λμ μκ°λ λ릴 λΏ λλ¬ λ©λͺ¨λ¦¬ μ¬μ©λμ κ±°μ μ΅νμμλ€..
κ·Έλμ 맨 μ²μ ν λ²λ§ μ΅λκ°μ ꡬνκ³ λΉκ΅λ₯Ό νλ μ€νμκ°, λ©λͺ¨λ¦¬ μ¬μ©λμ΄ λμ λκ² μ’μμ‘λ€.
from typing import List
class Solution:
def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:
answer = []
max_val = max(candies)
for val in candies:
if val + extraCandies >= max_val:
answer.append(True)
else:
answer.append(False)
return answer
Leave a comment