upd
This commit is contained in:
14
algorithms/labs/lab7/leetcode/2/solution.py
Normal file
14
algorithms/labs/lab7/leetcode/2/solution.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from typing import List
|
||||
|
||||
|
||||
class Solution:
|
||||
def candy(self, ratings: List[int]) -> int:
|
||||
n = len(ratings)
|
||||
candies = [1] * n
|
||||
for i in range(1, n):
|
||||
if ratings[i] > ratings[i - 1]:
|
||||
candies[i] = candies[i - 1] + 1
|
||||
for i in range(n - 2, -1, -1):
|
||||
if ratings[i] > ratings[i + 1]:
|
||||
candies[i] = max(candies[i], candies[i + 1] + 1)
|
||||
return sum(candies)
|
||||
Reference in New Issue
Block a user