Kids With the Greatest Number of Candies LeetCode solution in Python

1
class Solution:
2
def kidsWithCandies(self, candy, extra):
3
# create an array(res) with all values as True and it's lenght is same as candies
4
res = [True] * len(candy)
5
# iterate over the elements in the array candy
6
for i in range(len(candy)):
7
# if the no. of canides at curr position + extra is greater than or equal to the maximum of candies then continue
8
if (candy[i] + extra) >= max(candy):
9
continue
10
# if not
11
else:
12
# change the value of that position in res as false
13
res[i] = False
14
# return the res list
15
return res

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0