当前位置:网站首页>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
边栏推荐
- Meta再放大招!VR新模型登CVPR Oral:像人一样「读」懂语音
- Asp.netcore利用dynamic简化数据库访问
- Fiori applications are shared through the enhancement of adaptation project
- Global and Chinese silicone defoamer production and marketing demand and investment forecast analysis report Ⓨ 2022 ~ 2027
- Listen in the network
- Detailed explanation of OSPF LSA of routing Foundation
- 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
- 网络中的listen
- 数字化转型再下一城,数字孪生厂商优锘科技宣布完成超3亿元融资
- Global and Chinese styrene acrylic lotion polymer development trend and prospect scale prediction report Ⓒ 2022 ~ 2028
猜你喜欢
随机推荐
受益互联网出海 汇量科技业绩重回高增长
Professor Li Zexiang, Hong Kong University of science and technology: I'm wrong. Why is engineering consciousness more important than the best university?
详细讲解面试的 IO多路复用,select,poll,epoll
Zabbix 6.0 源码安装以及 HA 配置
启动solr报错The stack size specified is too small,Specify at least 328k
Spark source code reading outline
Social distance (cow infection)
Report on the "14th five year plan" and investment strategy recommendations for China's industrial robot industry 2022 ~ 2028
逆向调试入门-PE结构-输入表输出表05/07
Yarn restart applications record recovery
Beidou communication module Beidou GPS module Beidou communication terminal DTU
CV顶会最佳论文得主分享:好论文是怎么炼成的?
Fiori applications are shared through the enhancement of adaptation project
A Fletter version of Notepad
arthas使用
JS discolored Lego building blocks
Wave animation color five pointed star loader loading JS special effects
盲盒NFT数字藏品平台系统开发(搭建源码)
mysql统计账单信息(下):数据导入及查询
图灵奖得主Judea Pearl:最近值得一读的19篇因果推断论文









