Skip to content

Fix coin change #2571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 23, 2020
17 changes: 10 additions & 7 deletions dynamic_programming/coin_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
"""


def dp_count(S, m, n):
def dp_count(S, n):
"""
>>> dp_count([1, 2, 3], 3, 4)
>>> dp_count([1, 2, 3], 4)
4
>>> dp_count([1, 2, 3], 3, 7)
>>> dp_count([1, 2, 3], 7)
8
>>> dp_count([2, 5, 3, 6], 4, 10)
>>> dp_count([2, 5, 3, 6], 10)
5
>>> dp_count([10], 1, 99)
>>> dp_count([10], 99)
0
>>> dp_count([4, 5, 6], 3, 0)
>>> dp_count([4, 5, 6], 0)
1
>>> dp_count([1, 2, 3], -5)
0
"""

if n < 0:
return 0
# table[i] represents the number of ways to get to amount i
table = [0] * (n + 1)

Expand Down