标签:class blog code tar com get
void dfs(int k,int target,vector<int>& candidates,vector<int>& sol,vector<vector<int> >& res){ if(target==0){ vector<int> temp(sol); res.push_back(temp); return; }else if(target<0){ return; }else{ for(int i=k;i<candidates.size();i++){ if(candidates[i]>target) break; sol.push_back(candidates[i]); dfs(i,target-candidates[i],candidates,sol,res); sol.pop_back(); } } } vector<vector<int> > combinationSum(vector<int> &candidates, int target) { vector<vector<int> > res; vector<int> sol; sort(candidates.begin(),candidates.end()); dfs(0,target,candidates,sol,res); return res; }
leetcode Combination Sum,布布扣,bubuko.com
标签:class blog code tar com get
原文地址:http://www.cnblogs.com/xiexiaobo/p/3787764.html