分糖果,这题纯考察数学知识,当然我就简单来做了,数学列在下半年的学习计划中。
func distributeCandies(candies, numPeople int) []int { ans := make([]int, numPeople) i := 0 for candies != 0 { if candies < i + 1 { ans[i%numPeople] += candies candies -= candies } else { ans[i%numPeople] += i+1 candies -= i+1 } i += 1 } return ans }