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 744656e commit d745086Copy full SHA for d745086
combination-sum/prograsshopper.py
@@ -0,0 +1,17 @@
1
+class Solution:
2
+ def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
3
+ # Time complexity: O(n ^ (T / m))
4
+ result = []
5
+
6
+ def dfs(remain_sum, index, path):
7
+ if remain_sum < 0:
8
+ return
9
+ if remain_sum == 0:
10
+ result.append(path)
11
12
13
+ for i in range(index, len(candidates)):
14
+ dfs(remain_sum - candidates[i], i, path + [candidates[i]])
15
16
+ dfs(target, 0, [])
17
+ return result
0 commit comments