2
void combination(vector<int> &candidates, int target, vector<int> currComb, int currSum,3
int currIndex, vector<vector<int>> &ans) {4
if (currSum > target) return; // backtrack5
if (currSum == target) {6
ans.push_back(currComb); // store the solution and backtrack10
for (int i = currIndex; i < candidates.size();11
i++) { // try all possible options for the next level12
currComb.push_back(candidates[i]); // put 1 option into the combination13
currSum += candidates[i];14
combination(candidates, target, currComb, currSum, i,15
ans); // try with this combination, whether it gives a17
currComb.pop_back(); // when this option backtrack to here, remove this18
// and go on to the next option.19
currSum -= candidates[i];24
vector<vector<int>> combinationSum(vector<int> &candidates, int target) {25
vector<vector<int>> ans;27
combination(candidates, target, currComb, 0, 0, ans);