Skip to content

Commit af6fbba

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

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

coin-change/evan.py

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

0 commit comments

Comments
 (0)