一:题目
二:上码
class Solution {
public:vector<vector<int> >ans;vector<int>path;void backstacking(vector<int>&v,int num,int index) {int sum = accumulate(path.begin(),path.end(),0);if(sum > num) {return ;}if(sum == num) {ans.push_back(path);return ;}for(int i = index; i < v.size(); i++) {if(i > index && v[i] == v[i-1]) continue;path.push_back(v[i]);backstacking(v,num,i+1);path.pop_back(); }}vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {sort(candidates.begin(),candidates.end()); backstacking(candidates,target,0);return ans;}
};