当前位置:网站首页>20220527动态规划:零钱兑换
20220527动态规划:零钱兑换
2022-08-09 02:37:00 【丿SeeYouAgain】
题目描述:给你一个整数数组 coins
,表示不同面额的硬币;以及一个整数 amount
,表示总金额。计算并返回可以凑成总金额所需的 最少的硬币个数 。如果没有任何一种硬币组合能组成总金额,返回 -1
。你可以认为每种硬币的数量是无限的。
编码实现:
public int coinChange(int[] coins, int amount) {
int[] dp = new int[amount+1];
for(int i = 1;i <= amount; i++){
int min = Integer.MAX_VALUE;
for(int coin: coins){
if(i >= coin && dp[i-coin] < min){
min = dp[i-coin] + 1;
}
}
dp[i] = min;
}
return dp[amount] == Integer.MAX_VALUE ? -1 : dp[amount];
}
边栏推荐
- The first lesson of HNUMSC-C language
- 带你做接口测试从零到第一条用例 总结
- Financial Industry Software Testing Interview Questions (with Answers) | Getting Started Guide
- 数字 01 Vivado2018.2安装及实操
- The most fierce "employee" in history, madly complaining about the billionaire boss Xiao Zha: So rich, he always wears the same clothes!
- Appium常用操作及H5页面元素定位
- 并查集相关知识点
- gpio子系统和pinctrl子系统(中)
- 2022年最流行的自动化测试工具有哪些?全网最全最细都在这里了
- 时间复杂度和空间复杂度
猜你喜欢
全文翻译:Multimodal Neural Networks: RGB-D for Segmantic Segmentation and Object Detection
2022年自然语言处理校招社招实习必备知识点盘点分享
Likou Brush Question Record 6.1-----203. Remove linked list elements
【AspNetCore】实现JWT(使用Microsoft.AspNetCore.Authentication.JwtBearer)
online schema change and create index
Postman接口测试【官网】最新版本 安装及使用入门教程
jmeter的websocket插件安装和使用方法
gpio子系统和pinctrl子系统(上)
<爆>2022中文版-《海外博士申请指南-材料准备、时间线、套磁、面试及录取》免费分享
[ANT]apache ant 安装说明
随机推荐
Appium常用操作及H5页面元素定位
MT4 / MQ4L entry to the master of EA tutorial lesson two (2) - - MQL language commonly used function account information commonly used functions
9.1-----24. Swap the nodes in the linked list in pairs
313. 超级丑数-暴力解法
Simple example of .reduce()
腾讯地图获取定位
Solve the Final Fantasy 13-2 Clock Puzzle with DFS
2022年最流行的自动化测试工具有哪些?全网最全最细都在这里了
online schema change and create index
数字 05 verilog&vivado2018.2零散笔记
Take you do interface test from zero to the first case summary
企业从云服务的承诺支出中获得最大收益的四种方法
JS 截取数组的最后几个元素
HMS Core分析服务智能运营6.5.1版本上线
“蔚来杯“2022牛客暑期多校训练营7,签到题CFGJ
普通人如何增加收入
spark RDD转换算子 sample
10.1-----19. Delete the Nth node from the bottom of the linked list
Pytest+request+Allure实现接口自动化框架
使用TensorRT对AlphaPose模型进行加速