题目:
题解:
class Solution:def candy(self, ratings: List[int]) -> int:n = len(ratings)ret = 1inc, dec, pre = 1, 0, 1for i in range(1, n):if ratings[i] >= ratings[i - 1]:dec = 0pre = (1 if ratings[i] == ratings[i - 1] else pre + 1)ret += preinc = preelse:dec += 1if dec == inc:dec += 1ret += decpre = 1return ret