1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public int[] distributeCandies(int candies, int num_people) { int[] res = new int[num_people];
int candy = 1; while (candies > 0) { for (int i = 0; i < res.length && candies > 0; i++) { res[i] += candies - candy >= 0 ? candy : candies; candies -= candy; candy++; } }
return res; } }
|
References
1103. Distribute Candies to People