欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Test for change word to publish on cnblogs

程序员文章站 2022-06-30 17:36:53
test for change private: vector> res; vector path; vector candidates; public: void helper(int start,int target){ if (target> combinationSum(vector& ca... ......

test for change

 

 

private:

vector<vector<int>> res;

vector<int> path;

vector<int> candidates;

public:

 

void helper(int start,int target){

if (target<0){

return;

}else if(0==target){

res.push_back(path);

}else{

for(int i=start;i<candidates.size();i++){

if(candidates[i]<=target){

path.push_back(candidates[i]);

helper(i,target-candidates[i]);

path.pop_back();

}

}

}

}

vector<vector<int>> combinationsum(vector<int>& candidates, int target) {

 

sort(candidates.begin(),candidates.end());

vector<int> path;

this->candidates=candidates;

helper(0,target);

return res;

}

};

 

/*bool isexist(vector<vector<int>>& res, vector<int> path){

bool flag=false;

for(int i=0;i<res.size();i++){

for(int j=0;j<path.size();j++){

if(res[i][j]!=path[j]){

flag=false;

break;

}

else{

flag=true;

}

}

if(flag==true){

break;

}

}

return flag;

}*/