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 3e6706a commit bab86ffCopy full SHA for bab86ff
coin-change/samthekorean.py
@@ -0,0 +1,17 @@
1
+# a is number of amount and c is number of coins
2
+# TC : O(a∗c)
3
+# SC: O(a)
4
+class Solution:
5
+ def coinChange(self, denominations: List[int], target_amount: int) -> int:
6
+ minimum_coins = [target_amount + 1] * (target_amount + 1)
7
+ minimum_coins[0] = 0
8
+
9
+ for current_amount in range(1, target_amount + 1):
10
+ for coin in denominations:
11
+ if current_amount - coin >= 0:
12
+ minimum_coins[current_amount] = min(
13
+ minimum_coins[current_amount],
14
+ 1 + minimum_coins[current_amount - coin],
15
+ )
16
17
+ return minimum_coins[-1] if minimum_coins[-1] != target_amount + 1 else -1
0 commit comments