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 ff42bed commit 9eb0fb8Copy full SHA for 9eb0fb8
combination-sum/samthekorean.py
@@ -0,0 +1,19 @@
1
+# TC : O(n^2)
2
+# SC : O(n)
3
+class Solution:
4
+ def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
5
+ result = []
6
+
7
+ def dfs(start: int, total: int, current_combination: List[int]):
8
+ if total > target:
9
+ return
10
+ if total == target:
11
+ result.append(current_combination[:])
12
13
+ for i in range(start, len(candidates)):
14
+ current_combination.append(candidates[i])
15
+ dfs(i, total + candidates[i], current_combination)
16
+ current_combination.pop()
17
18
+ dfs(0, 0, [])
19
+ return result
0 commit comments