Skip to content

Commit f1ba297

Browse files
author
sejineer
committed
combination-sum solution
1 parent 7fb7220 commit f1ba297

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

combination-sum/sejineer.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
시간 복잡도: O(target * n)
3+
공간 복잡도: O(n)?
4+
개인적으로 어려웠던 문제라서 정답을 봤습니다.
5+
추후에 다시 복습할 예정입니다.
6+
"""
7+
class Solution:
8+
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
9+
dp = [[] for _ in range(target + 1)]
10+
dp[0] = [[]]
11+
for candidate in candidates:
12+
for num in range(candidate, target + 1):
13+
for combination in dp[num - candidate]:
14+
dp[num].append(combination + [candidate])
15+
return dp[target]

0 commit comments

Comments
 (0)