标签:
class Solution { public: vector<vector<int>> combinationSum(vector<int>& candidates, int target) { vector<vector<int>> path; vector<int> p; sort(candidates.begin(),candidates.end()); help(0,target,candidates,path,p); return path; } void help(int index,int target,vector<int>& candidates,vector<vector<int>> &path,vector<int> &p){ int i; for(i=index;i<candidates.size();i++){ if(target < candidates[i]) { return; } p.push_back(candidates[i]); if(target == candidates[i]) { path.push_back(p); p.pop_back(); return; } help(i,target-candidates[i],candidates,path,p); p.pop_back(); } return; } };
标签:
原文地址:http://www.cnblogs.com/julie-yang/p/4734508.html