# 39 Combination Sum

## 1. Question

Given a set of candidate numbers (C)(without duplicates)and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.
Thesamerepeated number may be chosen fromCunlimited 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:
[
[7],
[2, 2, 3]
]

## 2. Implementation

(1) Backtracking
class Solution {
public List<List<Integer>> combinationSum(int[] candidates, int target) {
List<List<Integer>> res = new ArrayList<>();
List<Integer> combinations = new ArrayList<>();
getCombinations(candidates, 0, 0, target, combinations, res);
return res;
}
public void getCombinations(int[] candidates, int index, int sum, int target, List<Integer> combinations, List<List<Integer>> res) {
if (sum > target) {
return;
}
if (sum == target) {
return;
}
for (int i = index; i < candidates.length; i++) {