Skip to content

Commit 3dba59a

Browse files
committed
Runtime: 210 ms (Top 78.26%) | Memory: 16.7 MB (Top 74.66%)
1 parent dc6d868 commit 3dba59a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

scripts/algorithms/C/Candy/Candy.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1+
// Runtime: 210 ms (Top 78.26%) | Memory: 16.7 MB (Top 74.66%)
12
class Solution:
23
def candy(self, ratings: List[int]) -> int:
34
n=len(ratings)
45
temp = [1]*n
5-
6+
67
for i in range(1,n):
78
if(ratings[i]>ratings[i-1]):
89
temp[i]=temp[i-1]+1
910
if(n>1):
1011
if(ratings[0]>ratings[1]):
1112
temp[0]=2
12-
13-
13+
1414
for i in range(n-2,-1,-1):
1515
if(ratings[i]>ratings[i+1] and temp[i]<=temp[i+1]):
1616
temp[i]=temp[i+1]+1
1717

18-
19-
return sum(temp)
18+
return sum(temp)

0 commit comments

Comments
 (0)