Skip to content

Commit e594c05

Browse files
authored
Create 322-Coin-Change.py
1 parent 39a2061 commit e594c05

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

322-Coin-Change.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def coinChange(self, coins: List[int], amount: int) -> int:
3+
dp = [amount + 1] * (amount + 1)
4+
dp[0] = 0
5+
6+
for a in range(1, amount + 1):
7+
for c in coins:
8+
if a - c >= 0:
9+
dp[a] = min(dp[a], 1 + dp[a - c])
10+
return dp[amount] if dp[amount] != amount + 1 else -1

0 commit comments

Comments
 (0)