Skip to content

Commit de096ec

Browse files
committed
feat: week3 - combination-sum
1 parent 96020a9 commit de096ec

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'''
2+
Approach
3+
- target๊ฐ’์—์„œ candidate ๊ฐ’์„ ๋นผ๊ณ  ๊ทธ ๋ˆ„์ ํ•ฉ์„ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค๋Š” ํ๋ฆ„์€ ํŒŒ์•…ํ–ˆ์ง€์ง€๋งŒ ๊ตฌํ˜„์ด ์–ด๋ ค์› ์Šต๋‹ˆ๋‹ค.
4+
-๊ทธ๋ž˜์„œ ์•Œ๊ณ ๋‹ฌ๋ ˆ๋ฅผ ์ฐธ๊ณ ํ•ด์„œ ์ตœ๋Œ€ํ•œ ์ดํ•ดํ•˜๊ณ  ํ˜ผ์ž ์ž‘์„ฑํ•ด๋ณด๋ ค๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค....
5+
'''
6+
class Solution:
7+
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
8+
dp = [[] for _ in range(target + 1)]
9+
dp[0] = [[]]
10+
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)