Skip to content

Commit f325658

Browse files
authored
Create Solution.java
1 parent 1d2980c commit f325658

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
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+
for (int i = 0, cur = 1; candies > 0; ++i, ++cur) {
5+
if (i == num_people) {
6+
i = 0;
7+
}
8+
if (candies >= cur) {
9+
res[i] += cur;
10+
candies -= cur;
11+
} else {
12+
res[i] += candies;
13+
candies = 0;
14+
}
15+
}
16+
return res;
17+
}
18+
}

0 commit comments

Comments
 (0)