class Solution: # @param ratings, a list of integer # @return an integer def candy(self, ratings): n=len(ratings) candynum=[1]*n for i in range(1,n): if ratings[i]>ratings[i-1]: candynum[i]=candynum[i-1]+1 for i in reversed(range(n-1)): if ratings[i]>ratings[i+1] and candynum[i]<=candynum[i+1]: candynum[i]=candynum[i+1]+1 return sum(candynum)
Friday, September 19, 2014
Leetcode: Candy @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment