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 0911277 commit 00093a4Copy full SHA for 00093a4
1 file changed
combination-sum/jylee2033.py
@@ -0,0 +1,22 @@
1
+class Solution:
2
+ def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
3
+ output = []
4
+
5
+ def backtrack(remain, comb, start):
6
+ if remain == 0:
7
+ output.append(list(comb))
8
+ return
9
10
+ elif remain < 0:
11
12
13
+ for i in range(start, len(candidates)):
14
+ comb.append(candidates[i])
15
+ backtrack(remain - candidates[i], comb, i)
16
+ comb.pop()
17
18
+ backtrack(target, [], 0)
19
+ return output
20
21
+# Time Complexity : O(N^T/M) N - number of candidates, T - target, M - minimum value in candidates
22
+# Space Complexity : O(T/M) - maximum depth of the recursion tree
0 commit comments