classSolution(object): defcombinationSum2(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] """ candidates.sort() result = [] path = [] self.dfs(candidates, path, result, target) return result defdfs(self, candidates, path, result, target): if target == 0: result.append(path[:]) return pre = None for item, value in enumerate(candidates): if pre isNoneor pre != value: if target < value: return path.append(value) self.dfs(candidates[item+1:], path, result, target-value) path.pop() pre = value