1 Star 0 Fork 0

蓝桥云课/python-100

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
062-coin_change.py 790 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaoyi733112 提交于 2020-03-03 17:57 . python-100 answer
class CoinChanger(object):
def make_change(self, coins, total):
if coins is None or total is None:
return None
if not coins or total == 0:
return 0
coins = [0] + coins
num_rows = len(coins)
num_cols = total + 1
T = [[None] * num_cols for _ in range(num_rows)]
for i in range(num_rows):
for j in range(num_cols):
if i == 0:
T[i][j] = 0
continue
if j == 0:
T[i][j] = 1
continue
if coins[i] <= j:
T[i][j] = T[i - 1][j] + T[i][j - coins[i]]
else:
T[i][j] = T[i - 1][j]
return T[num_rows - 1][num_cols - 1]
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/lanqiao-courses/python-100.git
git@gitee.com:lanqiao-courses/python-100.git
lanqiao-courses
python-100
python-100
master

搜索帮助