题目:
题解:
func candy(ratings []int) int {n := len(ratings)ans, inc, dec, pre := 1, 1, 0, 1for i := 1; i < n; i++ {if ratings[i] >= ratings[i-1] {dec = 0if ratings[i] == ratings[i-1] {pre = 1} else {pre++}ans += preinc = pre} else {dec++if dec == inc {dec++}ans += decpre = 1}}return ans
}