Leetcode 322 Solution
This article provides solution to leetcode question 322 (coin-change)
Access this page by simply typing in "lcs 322" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/coin-change
Solution
class Solution:
def coinChange(self, coins: List[int], amount: int) -> int:
dp = [sys.maxsize] * (amount + 1)
dp[0] = 0
for i in range(len(dp)):
for coin in coins:
if i - coin >= 0:
dp[i] = min(dp[i], dp[i - coin] + 1)
return dp[amount] if dp[amount] != sys.maxsize else -1