未验证 提交 46af42d4 编写于 作者: H Himadri Ganguly 提交者: GitHub

Fix coin change (#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: NTapajyoti Bose <44058757+ruppysuppy@users.noreply.github.com>

* 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: NTapajyoti Bose <44058757+ruppysuppy@users.noreply.github.com>
上级 04fae4db
......@@ -7,20 +7,23 @@ https://www.hackerrank.com/challenges/coin-change/problem
"""
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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册