Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def candy(self, ratings: List[int]) -> int:
- n = len(ratings)
- standings = [(rate, index) for index, rate in enumerate(ratings)]
- standings.sort()
- candies = [1]*n
- for rate, person in standings:
- if person-1 >= 0 and ratings[person-1] < ratings[person]:
- candies[person] = max(candies[person], candies[person-1]+1)
- if person+1 < n and ratings[person+1] < ratings[person]:
- candies[person] = max(candies[person], candies[person+1]+1)
- return sum(candies)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement