Skip to content

Commit 59c596a

Browse files
committed
feat: Coin Change
1 parent cf0b643 commit 59c596a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

coin-change/HodaeSsi.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# space complexity: O(n) (여기서 n은 amount)
2+
# time complexity: O(n * m) (여기서 n은 amount, m은 coins의 길이)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def coinChange(self, coins: List[int], amount: int) -> int:
8+
dp = [float('inf')] * (amount + 1)
9+
dp[0] = 0
10+
11+
for i in range(1, amount + 1):
12+
for coin in coins:
13+
if coin <= i:
14+
dp[i] = min(dp[i], dp[i - coin] + 1)
15+
16+
return dp[amount] if dp[amount] != float('inf') else -1
17+

0 commit comments

Comments
 (0)