Skip to content

Commit 819606d

Browse files
author
jinbeom
committed
Combination Sum Solution
1 parent 43ba99c commit 819606d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

combination-sum/kayden.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 시간복잡도: O(N^M)
2+
# 공간복잡도: O(M)
3+
class Solution:
4+
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
5+
res = []
6+
7+
def dfs(total, idx, path):
8+
if total < 0:
9+
return
10+
elif total == 0:
11+
res.append(path[:])
12+
13+
for i in range(idx, len(candidates)):
14+
dfs(total - candidates[i], i, path + [candidates[i]])
15+
16+
dfs(target, 0, [])
17+
18+
return res

0 commit comments

Comments
 (0)