当前位置:网站首页>leetcode 322. Coin change (medium)
leetcode 322. Coin change (medium)
2022-07-01 13:29:00 【InfoQ】
One 、 The main idea of the topic
- 1 <= coins.length <= 12
- 1 <= coins[i] <= 231 - 1
- 0 <= amount <= 104
Two 、 Their thinking
3、 ... and 、 How to solve the problem
3.1 Java Realization
public class Solution {
public int coinChange(int[] coins, int amount) {
if (coins.length == 0) {
return -1;
}
int[] dp = new int[amount + 1];
Arrays.fill(dp, amount + 2);
dp[0] = 0;
for (int i = 1; i <= amount; i++) {
for (int coin : coins) {
if (i >= coin) {
dp[i] = Math.min(dp[i], dp[i - coin] + 1);
}
}
}
return dp[amount] == amount + 2 ? -1 : dp[amount];
}
}
Four 、 Summary notes
- 2022/7/1 It's Friday , Today is a connecting day
边栏推荐
- Simple two ball loading
- 二传感器尺寸「建议收藏」
- mysql统计账单信息(下):数据导入及查询
- 香港科技大学李泽湘教授:我错了,为什么工程意识比上最好的大学都重要?
- 学历、长相、家境普通的人,未来的发展方向是什么?00后的职业规划都已经整得明明白白......
- MySQL gap lock
- Asp.netcore利用dynamic简化数据库访问
- Colorful five pointed star SVG dynamic web page background JS special effect
- Meta再放大招!VR新模型登CVPR Oral:像人一样「读」懂语音
- 机器学习总结(一):线性回归、岭回归、Lasso回归
猜你喜欢

IO的几种模型 阻塞,非阻塞,io多路复用,信号驱动和异步io

The future of game guild in decentralized games

Fiori applications are shared through the enhancement of adaptation project

SVG钻石样式代码

Nexus builds NPM dependent private database

Function test process in software testing

La taille de la pile spécifiée est petite, spécifiée à la sortie 328k

学历、长相、家境普通的人,未来的发展方向是什么?00后的职业规划都已经整得明明白白......

Colorful five pointed star SVG dynamic web page background JS special effect

Spark source code (V) how does dagscheduler taskscheduler cooperate with submitting tasks, and what is the corresponding relationship between application, job, stage, taskset, and task?
随机推荐
Wave animation color five pointed star loader loading JS special effects
Function test process in software testing
leetcode 322. Coin Change 零钱兑换(中等)
Terminal identification technology and management technology
Router. use() requires a middleware function but got a Object
Meta enlarge again! VR new model posted on CVPR oral: read and understand voice like a human
Leetcode第一题:两数之和(3种语言)
Have you ever encountered the problem that flynk monitors the PostgreSQL database and checkpoints cannot be used
Nexus builds NPM dependent private database
关于佛萨奇2.0“Meta Force原力元宇宙系统开发逻辑方案(详情)
Machine learning - performance metrics
二传感器尺寸「建议收藏」
Who should I know when opening a stock account? Is it actually safe to open an account online?
【机器学习】VAE变分自编码器学习笔记
Flutter SQLite使用
Operator-1 first acquaintance with operator
Different test techniques
In the next stage of digital transformation, digital twin manufacturer Youyi technology announced that it had completed a financing of more than 300 million yuan
Analysis report on the development prospect and investment strategic planning of China's wafer manufacturing Ⓔ 2022 ~ 2028
Sharing with the best paper winner of CV Summit: how is a good paper refined?