Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.
The same repeated number may be chosen from C unlimited number of times.
Note:
All numbers (including target) will be positive integers.
The solution set must not contain duplicate combinations.
For example, given candidate set [2, 3, 6, 7] and target 7,
A solution set is:
解法1:
经典的backtracking的做法。 一个可能的小改进是可以先对原数组进行排序,然后再判断target是否还大于当前可选的节点,这样可以提高一点效率。
C++
Java