使用python从递归函数返回列表

时间:2021-01-21 04:18:58

标签: python list recursion

 def helper(candidates, strt, target, arry):
    
    if target == 0:
        return arry
    if target < 0:
        return 
    for i in range(strt, len(candidates)):
        arry.append(candidates[i])
        helper(candidates, i, target-candidates[i], arry)
        arry.remove(candidates[i])
    return arry

coll = []
candidates = [2,3,6,7]
target = 7

coll = helper(candidates, 0, target, coll)

当我在主函数中打印 coll 时,我得到了空列表 我想从辅助函数返回 arry 中的所有附加值。 我该怎么做。

0 个答案:

没有答案
相关问题