当前位置:网站首页>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
边栏推荐
- 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
- Global and Chinese silicone defoamer production and marketing demand and investment forecast analysis report Ⓨ 2022 ~ 2027
- Introduction to reverse debugging PE structure input table output table 05/07
- Professor Li Zexiang, Hong Kong University of science and technology: I'm wrong. Why is engineering consciousness more important than the best university?
- C language learning
- 逆向调试入门-PE结构-输入表输出表05/07
- Who should I know when opening a stock account? Is it actually safe to open an account online?
- nexus搭建npm依赖私库
- Yarn restart applications record recovery
- Google Earth engine (GEE) - Global Human Settlements grid data 1975-1990-2000-2014 (p2016)
猜你喜欢
codeforces -- 4B. Before an Exam
Function test process in software testing
04-Redis源码数据结构之字典
Fiori 应用通过 Adaptation Project 的增强方式分享
JS变色的乐高积木
Fiori applications are shared through the enhancement of adaptation project
ZABBIX 6.0 source code installation and ha configuration
软件测试中功能测试流程
Wave animation color five pointed star loader loading JS special effects
Cs5268 advantages replace ag9321mcq typec multi in one docking station scheme
随机推荐
leetcode 322. Coin change (medium)
Apache-Atlas-2.2.0 独立编译部署
波浪动画彩色五角星loader加载js特效
The 14th five year plan of China's environmental protection industry and the report on the long-term goals for 2035 Ⓖ 2022 ~ 2028
mysql统计账单信息(下):数据导入及查询
内容审计技术
3.4 《数据库系统概论》之数据查询—SELECT(单表查询、连接查询、嵌套查询、集合查询、多表查询)
1.8 new features list
彩色五角星SVG动态网页背景js特效
Reasons for MySQL reporting 1040too many connections and Solutions
Application of 5g industrial gateway in scientific and technological overload control; off-site joint law enforcement for over limit, overweight and overspeed
受益互联网出海 汇量科技业绩重回高增长
Flow management technology
Router. use() requires a middleware function but got a Object
关于佛萨奇2.0“Meta Force原力元宇宙系统开发逻辑方案(详情)
Jenkins+webhooks- multi branch parametric construction-
VM virtual machine configuration dynamic IP and static IP access
啟動solr報錯The stack size specified is too small,Specify at least 328k
04-Redis源码数据结构之字典
Simple two ball loading