1. What I learned
a. method max()
‘max(List)’ returns the largest value in List.
2. How I sloved
I added elements of ‘candies’ and ‘extraCandies’ and compared them with the largest value in ‘candies’. If the sum of elements and ‘extraCandies’ exceeds the largest value, return ‘True’ otherwise return ‘False’.
3. Code
class Solution:
def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:
output_list = []
for candy in candies:
if candy+extraCandies >= max(candies):
output_list.append(True)
else:
output_list.append(False)
return output_list
4. Result
Runtime : 40 ms(59.94%), Memory usage : 13.9 MB(30.43%)
(Runtime can be different by a system even if it is a same code.)