Skip to content

Commit d2b8ff8

Browse files
committed
solve: coin change
1 parent 296255a commit d2b8ff8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

coin-change/evan.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def coinChange(self, coins, amount):
3+
dp = [float("inf")] * (amount + 1)
4+
dp[0] = 0
5+
6+
for currentAmount in range(1, amount + 1):
7+
for coin in coins:
8+
if currentAmount >= coin:
9+
dp[currentAmount] = min(
10+
dp[currentAmount], dp[currentAmount - coin] + 1
11+
)
12+
13+
return dp[amount] if dp[amount] != float("inf") else -1

0 commit comments

Comments
 (0)