Skip to content

Commit e37a16c

Browse files
authored
Create count-ways-to-distribute-candies.py
1 parent 09ec55f commit e37a16c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(n * k)
2+
# Space: O(k)
3+
4+
class Solution(object):
5+
def waysToDistribute(self, n, k):
6+
"""
7+
:type n: int
8+
:type k: int
9+
:rtype: int
10+
"""
11+
MOD = 10**9+7
12+
dp = [1]*(k+1)
13+
for i in xrange(1, n):
14+
for j in reversed(xrange(2, min(i, k)+1)):
15+
dp[j] = (j*dp[j] + dp[j-1]) % MOD
16+
return dp[k]

0 commit comments

Comments
 (0)