MCPcopy
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / ChangeMaking

Function ChangeMaking

Dynamic Programming.py:4–12  ·  view source on GitHub ↗
(coinVal, change)

Source from the content-addressed store, hash-verified

2# 输入需要找零的金额和货币的币值向量
3# 输出满足找零条件的最少的硬币个数
4def ChangeMaking(coinVal, change):
5 alist = [0]*(change+1)
6 for i in range(1, change+1):
7 temp = change; j = 0
8 while j <= len(coinVal)-1 and i >= coinVal[j]:
9 temp = min(alist[i-coinVal[j]], temp)
10 j += 1
11 alist[i] = temp + 1
12 return alist.pop()
13
14print(ChangeMaking([1, 5, 10, 25], 63))
15

Callers 1

Calls 1

popMethod · 0.45

Tested by

no test coverage detected