Skip to content

Commit fe5a044

Browse files
Fix coin change (TheAlgorithms#2571)
* Removed unused variable m. * Doctests are modified to match functions. * Added condition for negative values. * Fixed white-space around operator. * Fixed W293 blank line contains white-space error. * Update dynamic_programming/coin_change.py Co-authored-by: Tapajyoti Bose <[email protected]> * Fixed error in code. * Fixed whited spacing. * Fixed PEP8 error. * Added more test cases for coin change problem. * Removed extra test for negetive value. Co-authored-by: Tapajyoti Bose <[email protected]>
1 parent 893dd3f commit fe5a044

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Diff for: dynamic_programming/coin_change.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@
77
"""
88

99

10-
def dp_count(S, m, n):
10+
def dp_count(S, n):
1111
"""
12-
>>> dp_count([1, 2, 3], 3, 4)
12+
>>> dp_count([1, 2, 3], 4)
1313
4
14-
>>> dp_count([1, 2, 3], 3, 7)
14+
>>> dp_count([1, 2, 3], 7)
1515
8
16-
>>> dp_count([2, 5, 3, 6], 4, 10)
16+
>>> dp_count([2, 5, 3, 6], 10)
1717
5
18-
>>> dp_count([10], 1, 99)
18+
>>> dp_count([10], 99)
1919
0
20-
>>> dp_count([4, 5, 6], 3, 0)
20+
>>> dp_count([4, 5, 6], 0)
2121
1
22+
>>> dp_count([1, 2, 3], -5)
23+
0
2224
"""
23-
25+
if n < 0:
26+
return 0
2427
# table[i] represents the number of ways to get to amount i
2528
table = [0] * (n + 1)
2629

0 commit comments

Comments
 (0)