leetcode第332题,硬币找零,使用最少数量的指定硬币凑出目标数。
深度搜索,逐个加入硬币,当数额与目标数相等时,记录一下所用的硬币数,找出其中最小的就好了,但是这样做目标数很大的时候就会超时。
class Solution(object):
def coinChange(self, coins, amount):
"""
:type coins: List[int]
:type amount: int
:rtype: int
"""
def dfs(current, coinNum, coinNumList, amount):
if current == amount:
coinNumList.