class Solution {
public:
vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
vector<vector<int>> res;
vector<int> record;
getCombinationSum(res, record, candidates, target, 0);
return res;
}
private:
void getCombinationSum(vector<vector<int>>& res, vector<int>& record, vector<int>& candidates, int target, int start) {
if (target < 0) {
return;
}
if (target == 0) {
res.push_back(record);
return;
}
for (int i = start; i < candidates.size(); i++) {
record.push_back(candidates[i]);
getCombinationSum(res, record, candidates, target - candidates[i], i);
record.pop_back();
}
}
};