Skip to content

Commit f2a0399

Browse files
authored
Create number-of-people-aware-of-a-secret.py
1 parent a677f4d commit f2a0399

File tree

1 file changed

+18
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)