我正在解决硬币找零问题。我使用 leetcode 上的给定示例在 jupyter-notebook 上运行代码,并且可以正常工作。
同样的代码在 leetcode 上不起作用。导致语法错误:
复制代码如下:
def best_sum(target,nums):
dp=[None for y in range(target+1)]
dp[0]=[]
for i in range(len(dp)):
if dp[i]!=None:
for num in nums:
if i+num<=target:
combination=[*dp[i],num]
if dp[i+num]==None or len(combination)<len(dp[i+num]):
dp[i+num]=combination
return dp[-1]
best_sum(11,[1,2,5])