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 cbce8b1 commit c184b94Copy full SHA for c184b94
combination-sum/jinah92.py
@@ -0,0 +1,19 @@
1
+# O(T) time, O(C^T) space
2
+class Solution:
3
+ def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
4
+ results, nums = [], []
5
+
6
+ def dfs(start, total):
7
+ if total > target:
8
+ return
9
+ if total == target:
10
+ results.append(nums[:])
11
+ for i in range(start, len(candidates)):
12
+ num = candidates[i]
13
+ nums.append(num)
14
+ dfs(i, total + num)
15
+ nums.pop()
16
17
+ dfs(0, 0)
18
19
+ return results
0 commit comments