Skip to content

Commit bd7c413

Browse files
committed
feat: combination-sum
1 parent b9e028d commit bd7c413

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

combination-sum/HodaeSsi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 시간복잡도 : O(n * m) (n: target, m: len(candidates))
2+
# 공간복잡도 : O(n * m)
3+
class Solution:
4+
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
5+
dp = [[] for _ in range(target + 1)]
6+
dp[0] = [[]]
7+
8+
for candidate in candidates:
9+
for num in range(candidate, target + 1):
10+
for combination in dp[num - candidate]:
11+
temp = combination.copy()
12+
temp.extend([candidate])
13+
dp[num].append(temp)
14+
15+
return dp[target]
16+

0 commit comments

Comments
 (0)