思路:
// @Title: 分糖果 II (Distribute Candies to People)
// @Author: qisiii
// @Date: 2024-06-03 11:49:53
// @Runtime: 1 ms
// @Memory: 40.2 MB
// @comment:
// @flag:
class Solution {
public int[] distributeCandies(int candies, int num_people) {
int start = 0;
int[] result = new int[num_people];
int i = 0;
while (candies > 0) {
if (i == num_people) {
i = 0;
}
if (candies > start) {
result[i] += ++start;
} else {
result[i] += candies;
break;
}
i++;
candies = candies - start;
}
return result;
}
}