当前位置:网站首页>leetcode 322. Coin Change 零钱兑换(中等)
leetcode 322. Coin Change 零钱兑换(中等)
2022-07-01 13:18:00 【InfoQ】
一、题目大意
- 1 <= coins.length <= 12
- 1 <= coins[i] <= 231 - 1
- 0 <= amount <= 104
二、解题思路
三、解题方法
3.1 Java实现
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];
}
}
四、总结小记
- 2022/7/1 周五了,今天是个承上启下的日子
边栏推荐
- SSO and JWT good article sorting
- 【大型电商项目开发】性能压测-压力测试基本概念&JMeter-38
- 软件测试中功能测试流程
- 1553B环境搭建
- 3.4 《数据库系统概论》之数据查询—SELECT(单表查询、连接查询、嵌套查询、集合查询、多表查询)
- Anti fraud, refusing to gamble, safe payment | there are many online investment scams, so it's impossible to make money like this
- 新手准备多少钱可以玩期货?农产品可以吗?
- Apache-atlas-2.2.0 independent compilation and deployment
- What is the future development direction of people with ordinary education, appearance and family background? The career planning after 00 has been made clear
- word2vec训练中文词向量
猜你喜欢

简单的两个圆球loading加载

ROS2 Foxy depthai_ ROS tutorial

minimum spanning tree

Computer network interview knowledge points

SVG钻石样式代码

Fiori applications are shared through the enhancement of adaptation project

Operator-1 first acquaintance with operator

VM virtual machine configuration dynamic IP and static IP access

Build a vc2010 development environment and create a tutorial of "realizing Tetris game in C language"

Flow management technology
随机推荐
波浪动画彩色五角星loader加载js特效
Fiori 应用通过 Adaptation Project 的增强方式分享
学历、长相、家境普通的人,未来的发展方向是什么?00后的职业规划都已经整得明明白白......
MySQL statistical bill information (Part 2): data import and query
流量管理技术
硬件开发笔记(九): 硬件开发基本流程,制作一个USB转RS232的模块(八):创建asm1117-3.3V封装库并关联原理图元器件
ZABBIX 6.0 source code installation and ha configuration
数字化转型再下一城,数字孪生厂商优锘科技宣布完成超3亿元融资
启动solr报错The stack size specified is too small,Specify at least 328k
Global and Chinese silicone defoamer production and marketing demand and investment forecast analysis report Ⓨ 2022 ~ 2027
3.4 《数据库系统概论》之数据查询—SELECT(单表查询、连接查询、嵌套查询、集合查询、多表查询)
The future of game guild in decentralized games
Example code of second kill based on MySQL optimistic lock
Detailed explanation of parallel replication examples in MySQL replication
5. Use of ly tab plug-in of header component
Flutter SQLite使用
spark源码阅读总纲
Simple two ball loading
Vs code set code auto save
What is the future development direction of people with ordinary education, appearance and family background? The career planning after 00 has been made clear