text: from typing import List
  
  
  class Solution:
      def coinChange(self, coins: List[int], amount: int) -> int:
          dp = [float('inf')] * (amount + 1)
          dp[0] = 0
          if amount == 0:
              return 0
          for coin in coins:
              for i in range(coin, amount + 1):
                  dp[i] = min(dp[i], dp[i - coin] + 1)
          return dp[-1] if dp[-1] != float('inf') else -1
  