# Problem

Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.

Each number in C may only be used once in the combination.

Note:

• All numbers (including target) will be positive integers.
• The solution set must not contain duplicate combinations.

For example, given candidate set [10, 1, 2, 7, 6, 1, 5] and target 8,
A solution set is:

https://leetcode.com/problems/combination-sum-ii/#/description

# Solution

This problem can be solved using DFS:

• Get the result starting with the first number
• Get the result starting with the second number
• Get the result starting with the last number

But we need to sort the array first in order to remove duplicate records.

Share