We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
题目描述: 给你一个整数数组 coins ,表示不同面额的硬币;以及一个整数 amount ,表示总金额。
计算并返回可以凑成总金额所需的 最少的硬币个数 。如果没有任何一种硬币组合能组成总金额,返回 -1 。
你可以认为每种硬币的数量是无限的。 示例代码:
/** * @param {number[]} coins * @param {number} amount * @return {number} */ var coinChange = function(coins, amount) { let dp = new Array(amount + 1).fill(Infinity); dp[0] = 0; for(let i =1;i<=amount;i++){ for(const coin of coins) { if(i - coin >=0){ dp[i] = Math.min(dp[i],dp[i-coin]+1) } } } return dp[amount] === Infinity ? -1 : dp[amount]; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目描述:
给你一个整数数组 coins ,表示不同面额的硬币;以及一个整数 amount ,表示总金额。
计算并返回可以凑成总金额所需的 最少的硬币个数 。如果没有任何一种硬币组合能组成总金额,返回 -1 。
你可以认为每种硬币的数量是无限的。
示例代码:
The text was updated successfully, but these errors were encountered: