Skip to content

Commit a0279a0

Browse files
🔥 Day 17
1 parent 74ec2fc commit a0279a0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
## Week 3 🚧
2626
1. [Non-overlapping Intervals](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3425/) ➡️ [CPP Solution](Week3/eraseOverlapIntervals.cpp)
2727
2. [Best Time to Buy and Sell Stock III](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3426/) ➡️ [CPP Solution](Week3/maxProfit.cpp)
28+
3. [Distribute Candies to People](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3427/) ➡️ [CPP Solution](Week3/distributeCandies.cpp)
2829

2930
## Week 4 🚧
3031
Coming Soon...

Week3/distributeCandies.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
vector<int> distributeCandies(int candies, int n) {
4+
vector<int> people;
5+
people.assign(n, 0);
6+
7+
int i = 0;
8+
while(candies > 0) {
9+
people[i % n] += min(candies, i + 1);
10+
candies -= i + 1;
11+
++i;
12+
}
13+
14+
return people;
15+
}
16+
};

0 commit comments

Comments
 (0)