class Solution {
public:
vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {
vector<vector<int>> res;
vector<int> out;
sort(candidates.begin(), candidates.end());
helper(candidates, 0, target, out, res);
return res;
}
void helper(vector<int>& candidates, int pos, int target, vector<int>& out, vector<vector<int>>& res){
if(target<0) return;
else if(target==0) res.push_back(out);
else{
for(int i=pos;i<candidates.size();i++){
if(i!=pos && candidates[i]==candidates[i-1]) continue;
int t = candidates[i];
out.push_back(t);
helper(candidates, i+1, target-t, out, res);
out.pop_back();
}
}
}
};