Skip to content

Commit 626fc9f

Browse files
committed
combination-sum solution
1 parent 2423497 commit 626fc9f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

combination-sum/sungjinwi.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
시간 복잡도와 공간복잡도 추후 작성하겠습니다ㅠ
3+
풀이 보고 하루 뒤에 기억해서 해보려고 했는데도 한참 걸렸네요
4+
"""
5+
class Solution:
6+
def combinationSum(self, candidates: list[int], target: int) -> list[list[int]]:
7+
ans = []
8+
comb = []
9+
def recur(n : int):
10+
if sum(comb) > target :
11+
return
12+
elif sum(comb) == target :
13+
return ans.append(comb.copy())
14+
else :
15+
for i in range(n, len(candidates)) :
16+
comb.append(candidates[i])
17+
recur(i)
18+
comb.pop()
19+
recur(0)
20+
return ans

0 commit comments

Comments
 (0)