Skip to content

Commit a94548a

Browse files
committed
Runtime 47 ms (Top 23.44%) | Memory 13.0 MB (Top 53.64%)
1 parent 498a0e4 commit a94548a

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
# Runtime: 48 ms (Top 80.79%) | Memory: 13.9 MB (Top 16.98%)
2-
class Solution(object):
3-
def kidsWithCandies(self, candies, extraCandies):
4-
"""
5-
:type candies: List[int]
6-
:type extraCandies: int
7-
:rtype: List[bool]
8-
"""
9-
10-
maxCandies = 0
11-
for candy in candies :
12-
if candy >= maxCandies:
13-
maxCandies = candy
14-
15-
for i, candy in enumerate(candies):
16-
if candy + extraCandies >= maxCandies:
17-
candies[i] = True
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
1811
else:
19-
candies[i] = False
20-
return candies
12+
#change the value of that position in res as false
13+
res[i] = False
14+
#return the res list
15+
return res

0 commit comments

Comments
 (0)