问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图 def combinationSum(candidates, target):
ans = []
n = []
def backstscking(candidates,target,s,startindex):
if s>target:
return
if (s==target):
ans.append(n)
return
for i in range(startindex,len(candidates)):
n.append(candidates[i])
s += candidates[i]
backstscking(candidates,target,s,i)
s-=candidates[i]
n.pop()
backstscking(candidates,target,0,0)
return ans
candidates=[2,3,6,7]
target=7
print(combinationSum(candidates,target))