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 da6507b commit 6b7bef5Copy full SHA for 6b7bef5
combination-sum/daiyongg-kim.py
@@ -0,0 +1,26 @@
1
+class Solution:
2
+ def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
3
+ candidates.sort()
4
+ result = []
5
+
6
+ def backtracking(start_index, current_combination, current_sum):
7
+ if current_sum == target:
8
+ result.append(list(current_combination))
9
+ return
10
11
+ if current_sum > target:
12
13
14
+ for i in range(start_index, len(candidates)):
15
+ candidate = candidates[i]
16
17
+ if current_sum + candidate > target:
18
+ break
19
20
+ current_combination.append(candidate)
21
+ backtracking(i, current_combination, current_sum + candidate)
22
23
+ current_combination.pop()
24
25
+ backtracking(0, [], 0)
26
+ return result
0 commit comments