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 0199703 commit 78849adCopy full SHA for 78849ad
combination-sum/hi-rachel.py
@@ -0,0 +1,20 @@
1
+# DFS + 백트래킹
2
+# 중복 조합 문제
3
+# O(2^t) time, O(재귀 깊이 (t) + 결과 조합의 수 (len(result))) space
4
+
5
+class Solution:
6
+ def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
7
+ nums, result = [], []
8
+ def dfs(start, total):
9
+ if total > target:
10
+ return
11
+ if total == target:
12
+ result.append(nums[:])
13
+ for i in range(start, len(candidates)):
14
+ num = candidates[i]
15
+ nums.append(num)
16
+ dfs(i, total + num)
17
+ nums.pop()
18
19
+ dfs(0, 0)
20
+ return result
0 commit comments