Combination Sum II
[
[1, 7],
[1, 2, 5],
[2, 6],
[1, 1, 6]
]class Solution:
def combinationSum2(self, c: List[int], target: int) -> List[List[int]]:
c.sort()
res = []
n=len(c)
def dfs(pos,path,target):
if target == 0:
res.append(path)
for i in range(pos,n ):
if c[i] > target:
return
if i!=pos and c[i]==c[i-1]:
continue #!!!!!!
dfs(i+1,path+[c[i]],target - c[i])
dfs(0,[],target)
return res
Last updated