class Solution {
public:
vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {
vector<vector<int>> res;
vector<int> record;
vector<bool> used(candidates.size(), false);
sort(candidates.begin(), candidates.end());
getCombinationSum(res, record, candidates, used, target, 0);
return res;
}
private:
void getCombinationSum(vector<vector<int>>& res, vector<int>& record, vector<int>& candidates, vector<bool>& used, int target, int start) {
if (target < 0) {
return;
}
if (target == 0) {
res.push_back(record);
return;
}
for (int i = start; i < candidates.size(); i++) {
if (i > start && candidates[i] == candidates[i - 1]){
continue;
}
record.push_back(candidates[i]);
getCombinationSum(res, record, candidates, used, target - candidates[i], i + 1);
record.pop_back();
}
}
};