当前位置:网站首页>力扣:零钱兑换
力扣:零钱兑换
2022-06-21 20:32:00 【夕颜_hd99】
给你一个整数数组 coins ,表示不同面额的硬币;以及一个整数 amount ,表示总金额。
计算并返回可以凑成总金额所需的 最少的硬币个数 。如果没有任何一种硬币组合能组成总金额,返回 -1 。
你可以认为每种硬币的数量是无限的。
示例 1:
输入:coins =[1, 2, 5], amount =11输出:3解释:11 = 5 + 5 + 1
class Solution {
public int coinChange(int[] coins, int amount) {
int[] f = new int[amount+1];
int n = coins.length;
f[0] = 0;
for(int i = 1; i <= amount; ++i){
f[i] = Integer.MAX_VALUE;
for(int j = 0 ; j < n; ++j){
if(i >= coins[j] && f[i - coins[j]] != Integer.MAX_VALUE){
f[i] = Math.min(f[i - coins[j]] + 1 , f[i]);
}
}
}
if(f[amount] == Integer.MAX_VALUE){
f[amount] = -1;
}
return f[amount];
}
}边栏推荐
- Barbell strategy -- extreme stability and extreme waves
- 分别利用for、while、do while,循环求1-100的和
- B2B商城网站助力企业加快分销速度,构建高效智能的B2B网上分销平台
- 【深入理解TcaplusDB技术】Tmonitor后台一键安装
- Background and specificity of Worthington elastase
- 利用for循环,分别计算1-100中奇数的和、偶数的和【方法一】
- Chess and card games
- Beijing accelerates ecological construction, Medtronic Internet and Moore thread complete product compatibility and mutual certification
- Font size in DataGridView of C #
- Luogu p1535 [usaco08mar]cow traveling s problem solution
猜你喜欢

软件架构介绍

刷题笔记(十七)--二叉搜索树:关于属性问题

B2B商城网站助力企业加快分销速度,构建高效智能的B2B网上分销平台

Enterprise data leakage prevention solution sharing

C# AboutBox怎么显示自己定义的界面

British teddy bear joins the pubg mobile game
![[deeply understand tcapulusdb technology] tmonitor background one click installation](/img/f6/d2a287aac4ef3dfa8c75f7130202a4.png)
[deeply understand tcapulusdb technology] tmonitor background one click installation

从-1开始实现一个中间件

TRNA analysis using trnascan se

2022佛山潭洲陶瓷展召开新闻发布会 推出展会十大重点
随机推荐
先进封装,一个大周期的开始——“迎风国潮”半导体设备研讨会
HIC Pro | HIC data processing tool
opencvsharp阈值分割threshold函数的ThresholdTypes
央企国电集团上海翔伟机电和中外海达成战略合作,捐赠2亿
Luogu p1378 oil drop expansion problem solution
处理订单业务多面手,订货管理系统实现企业订货库存统一管理
Background and specificity of Worthington elastase
【深入理解TcaplusDB技术】单据受理之表管理
刷题笔记(十七)--二叉搜索树:关于属性问题
dotter|打点法进行序列两两比较软件
Leetcode question brushing: SF Technology Smart logistics Campus Technology Challenge
【深入理解TcaplusDB技术】TcaplusDB业务数据备份
高项-立项管理
Utilisation de la combinaison d'assertions de l'API Stream et de la mise en cache locale pour les requêtes floues (près de 1000 fois plus efficace que MySQL)
传承百年经典的瑞吉管家静待您的优雅旅程再次开启
A callback was made to a garbage collected delegate of type "xxx:: invoke". This can cause application crashes, corruption, and data loss. When passing delegates to unmanaged code, the managed applica
University of Virginia: ingy Elsayed aly | logic based reward formation in Multi-Agent Reinforcement Learning
GDB调试实战(8)给程序传递启动参数
Paml| Shengxin software for calculating dn/ds value
Worthington木瓜蛋白酶特异性和应用