Skip to content

Commit dd18aa5

Browse files
authored
Create Distribute Candies to People
1 parent 00ec76f commit dd18aa5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Distribute Candies to People

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int[] distributeCandies(int candies, int num_people) {
3+
int[] res = new int[num_people];
4+
int count = 1;
5+
int ix = 0;
6+
while(candies > 0){
7+
ix %= num_people;
8+
if(count > candies){
9+
count = candies;
10+
}
11+
res[ix++] += count;
12+
13+
candies -= count;
14+
count++;
15+
}
16+
return res;
17+
}
18+
}

0 commit comments

Comments
 (0)