2
def coinChange(self, coins: List[int], amount: int) -> int:5
# Values in this array equal the number of coins needed to achieve the cost of the index6
minCoins = [amount + 1] * (amount + 1)9
# Loop through every needed amount10
for i in range(amount + 1):11
# Loop through every coin value13
# Check that the coin is not bigger than the current amount15
# minCoins[i]: number of coins needed to make amount i16
# minCoins[i-coin]: number of coins needed to make the amount before adding17
# the current coin to it (+1 to add the current coin)18
minCoins[i] = min(minCoins[i], minCoins[i - coin] + 1)20
# Check if any combination of coins was found to create the amount21
if minCoins[amount] == amount + 1:24
# Return the optimal number of coins to create the amount25
return minCoins[amount]