class Solution {
public:
vector<int> distributeCandies(int candies, int num_people) {
vector<int> v(num_people);
int i = 0;
int j = 1;
while(true)
{
if(candies >= j)
{
v[i % num_people] += j;
candies -= j;
}
else
{
v[i % num_people] += candies;
break;
}
i++;
j++;
}
return v;
}
};
leetcode每日一题第108天
最新推荐文章于 2024-08-21 10:11:50 发布