File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -9,19 +9,19 @@ def candy(self, ratings):
9
9
children_nums = len (ratings )
10
10
11
11
# Scan from left to right
12
- for i in range (children_nums - 1 ):
13
- if ratings [i + 1 ] > ratings [i ]:
14
- candies [i + 1 ] = candies [i ] + 1
12
+ for i in range (children_nums - 1 ):
13
+ if ratings [i + 1 ] > ratings [i ]:
14
+ candies [i + 1 ] = candies [i ] + 1
15
15
else :
16
- candies [i + 1 ] = 1
16
+ candies [i + 1 ] = 1
17
17
18
18
minimum_candies = 0
19
19
# Scan from right to left
20
- for i in range (children_nums - 1 , 0 , - 1 ):
21
- if ratings [i - 1 ] > ratings [i ]:
22
- candies [i - 1 ] = max (candies [i ] + 1 , candies [i - 1 ])
20
+ for i in range (children_nums - 1 , 0 , - 1 ):
21
+ if ratings [i - 1 ] > ratings [i ]:
22
+ candies [i - 1 ] = max (candies [i ] + 1 , candies [i - 1 ])
23
23
else :
24
- candies [i - 1 ] = max (1 , candies [i - 1 ])
24
+ candies [i - 1 ] = max (1 , candies [i - 1 ])
25
25
minimum_candies += candies [i ]
26
26
27
27
return minimum_candies + candies [0 ]
You can’t perform that action at this time.
0 commit comments