Question
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:
1 |
|
Analysis
这道题是对之前Combination Sum的一个变形,这里有每个数字只能用一次的限制。解题上来看,还是一样的。只是需要考虑怎么来处理只用一次,之前我们每次内循环都还是从原来的数字index开始,这里我们只要每次用完一个数字就移到下一个数字就可以了。代码如下
Solution
1 |
|
1 |
|