class Solution {
public:
vector<vector<int>> result;
vector<int> path;
vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {
sort(candidates.begin(),candidates.end());
traverse(candidates,target,0);
return result;
}
void traverse(vector<int>& candidates, int target, int start_index){
if(target<=0){
if(target==0){
result.push_back(path);
}
return;
}
for(int i=start_index;i<candidates.size();i++){
if(i>0&&candidates[i]==candidates[i-1]&&i>start_index) continue;
path.push_back(candidates[i]);
traverse(candidates, target-candidates[i], i+1);
path.pop_back();
}
}
};