forked from suman-shah/cpp-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombination_sum.cpp
More file actions
19 lines (18 loc) · 499 Bytes
/
Copy pathcombination_sum.cpp
File metadata and controls
19 lines (18 loc) · 499 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public:
vector<vector<int>> ans;
void allc(vector<int>& cd,vector<int>& cur,int st,int tg){
if(tg<0)return;
if(tg==0){ans.push_back(cur);return;}
for(int i = st ; i<cd.size() ; i++){
cur.push_back(cd[i]);
allc(cd,cur,i,tg-cd[i]);
cur.pop_back();
}
}
vector<vector<int>> combinationSum(vector<int>& cd, int tg) {
vector<int> cur;
allc(cd,cur,0,tg);
return ans;
}
};