题目链接:https://leetcode-cn.com/problems/distribute-candies-to-people/
题目如下:
class Solution {
public:
vector<int> distributeCandies(int candies, int num_people) {
vector<int> result(num_people,0);
int count=1;
for(int i=0;i<num_people;i++){
if(candies>=count) result[i]+=count;
else {result[i]+=candies;return result;}
candies-=count++;
if(i+1==num_people) i=-1;
}
return result;
}
};