We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0160a7b commit c70a504Copy full SHA for c70a504
coin-change/bemelon.py
@@ -0,0 +1,16 @@
1
+class Solution:
2
+ # Space complexity: O(n)
3
+ # Time complexity: O(n * m)
4
+ # - n: amount
5
+ # - m: len(coins)
6
+ def coinChange(self, coins: list[int], amount: int) -> int:
7
+ INIT_VALUE = 999999999
8
+ dp = [INIT_VALUE] * (amount + 1)
9
+ dp[0] = 0
10
+
11
+ for x in range(1, amount + 1):
12
+ for coin in coins:
13
+ if x - coin >= 0:
14
+ dp[x] = min(dp[x], dp[x - coin] + 1)
15
16
+ return dp[amount] if dp[amount] != INIT_VALUE else -1
0 commit comments