class Solution: def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]: result = [] def dfs(idx, path): if sum(path) > target: return elif sum(path) == target: result.append(path[:]) return for i in range(idx, len(candidates)): if i > idx and candidates[i] == candidates[i-1]: continue path.append(candidates[i]) dfs(i + 1, path) path.pop() candidates.sort() dfs(0, []) return result