Skip to content

Commit 904339d

Browse files
Solve : Coin Change
1 parent 19d1776 commit 904339d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

coin-change/printjin-gmailcom.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def coinChange(self, coins, amount):
3+
dp = [float('inf')] * (amount + 1)
4+
dp[0] = 0
5+
for coin in coins:
6+
for x in range(coin, amount + 1):
7+
dp[x] = min(dp[x], dp[x - coin] + 1)
8+
return dp[amount] if dp[amount] != float('inf') else -1

0 commit comments

Comments
 (0)