class Solution:
def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:
candidates=sorted(candidates)
end=[]
def dfs(candidates,target,i,l):
if(sum(l)==target):
end.append(l.copy())
return
if(sum(l)>target or i==len(candidates)):
return
l.append(candidates[i])
dfs(candidates,target,i+1,l)
l.pop()
dfs(candidates,target,i+1,l)
dfs(candidates,target,0,[])
end=list(set(tuple(i) for i in end))
return end
讨巧的方式暴力解,这里值得注意的是list不能直接set,需要转tuple