Given distinct candidate numbers and a target, return every unique combination where the chosen numbers sum to the target.
You may use the same candidate more than once. The runner accepts the combinations in any order.
Build one partial choice at a time, recurse, then undo that choice before exploring the next option. Pay close attention to duplicate handling and stopping conditions.
Examples
Input: candidates = [2,3,6,7], target = 7 Output: [[2,2,3],[7]]
Input: candidates = [2,3,5], target = 8 Output: [[2,2,2,2],[2,3,3],[3,5]]
Constraints
- 1 <= candidates.length <= 30
- 2 <= candidates[i] <= 40
- All candidates are distinct.
- 1 <= target <= 40