Skip to content

Commit e0190f7

Browse files
committed
322
1 parent 864779b commit e0190f7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

coin-change/jeldo.py

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

0 commit comments

Comments
 (0)