Skip to content

Commit c184b94

Browse files
committed
feat: week3 medium 문제풀이(combination-sum)
1 parent cbce8b1 commit c184b94

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

combination-sum/jinah92.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)