classSolution:defcombinationSum2(self, candidates: List[int], target:int)-> List[List[int]]:
result =[]
candidates.sort()
self.backtrack(candidates, target,0,[],0, result)return result
# 传入参数defbacktrack(self, candidates, target, index, temp_list, cur, result):# 结束条件if cur == target:if temp_list notin result:
result.append(temp_list[:])elif cur > target:returnfor i inrange(index,len(candidates)):# 去重全是一样的数据if i > index and candidates[i]== candidates[i -1]:continue
cur += candidates[i]
temp_list.append(candidates[i])
self.backtrack(candidates, target, i +1,temp_list, cur, result)
cur -= candidates[i]
temp_list.pop()