class Solution:
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
end=[];
i=0;
tmp=[];
def dfs(candidates, target,tmp,i):
if sum(tmp)==target:
end.append(tmp.copy());
return;
if sum(tmp) > target or i>=len(candidates):
return;
tmp.append(candidates[i]);
dfs(candidates,target,tmp,i)
i+=1
tmp.pop();
dfs(candidates,target,tmp,i);
i+=1
dfs(candidates,target,tmp,i);
return end;
直接套模板解,没什么特别的地方,时空效率都不高