我有类似的问题需要链接:coin change algorithm in scala using recursion
代码是递归的,看起来像:
def countChange(money: Int, coins: List[Int]): Int = {
def count(capacity: Int, changes: List[Int]): Int = {
if(capacity == 0) 1
else if(capacity < 0) 0
else if(changes.isEmpty && capacity >=1 )0
else count(capacity, changes.tail) + count(capacity - changes.head, changes)
}
count(money, coins)
}
我的问题是如何分析此算法的时间复杂度?谢谢!