We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 139e89d commit 17c86e8Copy full SHA for 17c86e8
combination-sum/dylan-jung.cpp
@@ -0,0 +1,24 @@
1
+class Solution {
2
+public:
3
+ vector<vector<int>> ans;
4
+ vector<int> candids;
5
+ int t;
6
+
7
+ void dfs(int idx, int sum, vector<int> s) {
8
+ if(sum > t) return;
9
+ else if (sum == t) ans.push_back(s);
10
11
+ for(int i = idx; i < candids.size(); i++) {
12
+ auto next = vector<int>(s);
13
+ next.push_back(candids[i]);
14
+ dfs(i, sum+candids[i], next);
15
+ }
16
+ };
17
18
+ vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
19
+ candids = candidates;
20
+ t = target;
21
+ dfs(0, 0, {});
22
+ return ans;
23
24
+};
0 commit comments