当前位置:网站首页>Li Kou: Change
Li Kou: Change
2022-06-21 22:24:00 【Sunset_ hd99】
Give you an array of integers coins , Coins of different denominations ; And an integer amount , Represents the total amount .
Calculate and return the amount needed to make up the total amount The minimum number of coins . If no combination of coins can make up the total amount , return -1 .
You can think of the number of coins of each kind as infinite .
Example 1:
Input :coins =[1, 2, 5], amount =11Output :3explain :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];
}
}边栏推荐
- I2C【1】-I2C驱动调试读操作异常的bug
- 利用BioEdit做多序列一致性比对
- Leetcode question brushing: SF Technology Smart logistics Campus Technology Challenge
- An Chaoyun was selected as one of the "top ten cloud computing solution providers" in the Asia Pacific region by cioreview in 2022
- 【深入理解TcaplusDB技術】TcaplusDB構造數據
- dotter|打点法进行序列两两比较软件
- Beijing accelerates ecological construction, Medtronic Internet and Moore thread complete product compatibility and mutual certification
- Sampler collection
- HiCPlotter|HiC数据可视化工具
- 浅学Vector---如何使用常见的接口
猜你喜欢

刷题笔记(十六)--二叉树:修改与构造

InstaDeep Ltd:Arthur Flajolet | 单机上基于群体的快速强化学习

技术分享 | kubernetes pod 简介

使用StreamAPI 斷言組合,結合本地緩存做模糊查詢(比mysql效率提昇近1000倍)

力扣刷題集結4(mysql版本)
![[leetcode] 8. String conversion integer (ATOI)](/img/e8/08986237d8945685888817f214d7a9.png)
[leetcode] 8. String conversion integer (ATOI)

Zhengweimin, academician of the Chinese Academy of Engineering: I am optimistic that China will have a place in the next it Era

celery+rabbit分布式任务处理

Notes on question brushing (17) -- binary search tree: about attribute problems

浅学Vector---如何使用常见的接口
随机推荐
Using streamapi assertion combination and local cache for fuzzy query (nearly 1000 times more efficient than MySQL)
Using bioedit to do multiple sequence consistency alignment
Use the for loop to calculate the odd and even sums in 1-100 [method 1]
弗吉尼亚大学:Ingy ElSayed-Aly | 多智能体强化学习中的基于逻辑的奖励形成
vb屏幕分辨率设置和获取_hawkol_新浪博客
MitoZ|Multi-Kmer mode
Luogu p1378 oil drop expansion problem solution
IP-guard打印管控,防止打印渠道信息泄露
[deeply understand tcapulusdb technology] tmonitor background one click installation
利用for循环,分别计算1-100中奇数的和、偶数的和【方法二】
Communication failure between botu simulation HMI and real 1200plc
[deeply understand tcapulusdb technology] table management of document acceptance
RTX3090 与pytorch版本对应关系
Introduction to software architecture
How to write the title of popular popular items in our media video
从-1开始实现一个中间件
IQtree|构建进化树的软件
软件架构介绍
刷题笔记(十六)--二叉树:修改与构造
[deeply understand tcapulusdb technology] tmonitor module architecture