題庫
00:00

23. Coin Change

中等動態規劃AmazonMicrosoft

Given coin denominations and an amount, return the minimum number of coins needed, or -1 if the amount cannot be formed.

範例 1:

輸入: coins = [1,2,5], amount = 11
輸出: 3

範例 2:

輸入: coins = [2], amount = 3
輸出: -1

限制條件:

  • 1 <= coins.length <= 12
  • 0 <= amount <= 10^4
核心程式碼模式
● 已自動儲存第 1 行,第 1 欄