-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcandies.py
More file actions
38 lines (29 loc) · 912 Bytes
/
candies.py
File metadata and controls
38 lines (29 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from typing import List
class Solution:
def distributeCandies(self, candies: int, num_people: int) -> List[int]:
#Create empty array to represent number of people
np = [0] * num_people
count = 0
candieGift = 1
while candies > 0:
np[count % num_people] += candieGift
# Subtract the gifted candies from the count, and increment the next gift amount
candies -= candieGift
count += 1
if candies > candieGift:
candieGift += 1
else:
candieGift = candies
return np
def main():
sol = Solution()
candies1 = 7
candies2 = 10
candies3 = 9
people1 = 4
people2 = 3
people3 = 4
print(sol.distributeCandies(candies3, people3))
#print(sol.distributeCandies(candies2, people2))
if __name__ == "__main__":
main()