classSolution:defcombinationSum2(self,candidates: List[int],target:int) -> List[List[int]]:defdfs(tmp,sum,start):ifsum> target:returnelifsum== target: res.append(list(tmp))returnfor i inrange(start, n): num = candidates[i]if i-1>= start and num == candidates[i-1]:#已经使用过了,跳过,去重continuedfs(tmp + [num], sum+ num, i+1)#每个数字只用一次 candidates.sort() n =len(candidates) res = []dfs([], 0, 0)return res