1195. Distribute Candies to People
My accepted C++ solution to LeetCode problem 1195, Distribute Candies to People, running in 0ms.
- Difficulty: Easy
- C++
- Runtime 0ms
- Memory 8.9MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 8.9MB, accepted 2025-12-28.
class Solution {
public:
vector<int> distributeCandies(int candies, int num_people) {
vector<int> result(num_people, 0);
int give = 1;
int i = 0;
while (candies > 0) {
result[i % num_people] += min(give, candies);
candies -= give;
give++;
i++;
}
return result;
}
};