Skip to content

Commit 6bfe8de

Browse files
solves distribute candeis to people
1 parent bf77eab commit 6bfe8de

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

β€ŽREADME.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@
294294
| 1085 | πŸ”’ [Sum of Digits in Minimum Number](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number) | | |
295295
| 1086 | πŸ”’ [High Five](https://leetcode.com/problems/high-five) | | |
296296
| 1089 | [Duplicate Zeroes](https://leetcode.com/problems/duplicate-zeros) | [![Java](assets/java.png)](src/DuplicateZeros.java) | |
297-
| 1099 | [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k) | | |
298-
| 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) | | |
297+
| 1099 | πŸ”’ [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k) | | |
298+
| 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) | [![Java](assets/java.png)](src/DistributeCandiesToPeople.java) | |
299299
| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | | |
300300
| 1118 | [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month) | | |
301301
| 1119 | [Remove Vowels From String](https://leetcode.com/problems/remove-vowels-from-a-string) | | |

β€Žsrc/DistributeCandiesToPeople.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class DistributeCandiesToPeople {
2+
public int[] distributeCandies(int candies, int people) {
3+
final int[] result = new int[people];
4+
for (int i = 0, k = 1 ; candies > 0 ; k++, i = (i + 1) % people) {
5+
result[i] += Math.min(candies, k);
6+
candies -= Math.min(candies, k);
7+
}
8+
return result;
9+
}
10+
}

0 commit comments

Comments
Β (0)