当前位置:网站首页>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 周五了,今天是个承上启下的日子
边栏推荐
- 硬件开发笔记(九): 硬件开发基本流程,制作一个USB转RS232的模块(八):创建asm1117-3.3V封装库并关联原理图元器件
- Jenkins+webhooks-多分支参数化构建-
- 啟動solr報錯The stack size specified is too small,Specify at least 328k
- 基于mysql乐观锁实现秒杀的示例代码
- 网络中的listen
- 【机器学习】VAE变分自编码器学习笔记
- arthas使用
- SVG钻石样式代码
- Fiori 应用通过 Adaptation Project 的增强方式分享
- Build a vc2010 development environment and create a tutorial of "realizing Tetris game in C language"
猜你喜欢
MySQL statistical bill information (Part 2): data import and query
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
Terminal identification technology and management technology
Detailed explanation of OSPF LSA of routing Foundation
Different test techniques
Meta再放大招!VR新模型登CVPR Oral:像人一样「读」懂语音
spark源码(五)DAGScheduler TaskScheduler如何配合提交任务,application、job、stage、taskset、task对应关系是什么?
VM virtual machine configuration dynamic IP and static IP access
ROS2 Foxy depthai_ ROS tutorial
Content Audit Technology
随机推荐
Meta enlarge again! VR new model posted on CVPR oral: read and understand voice like a human
JS变色的乐高积木
Social distance (cow infection)
网络中的listen
1.8新特性-List
Build a vc2010 development environment and create a tutorial of "realizing Tetris game in C language"
数字化转型再下一城,数字孪生厂商优锘科技宣布完成超3亿元融资
彩色五角星SVG动态网页背景js特效
minimum spanning tree
Simple two ball loading
1553B环境搭建
Analysis report on the development prospect and investment strategy of the global and Chinese laser chip industry Ⓑ 2022 ~ 2027
Yarn重启applications记录恢复
Global and Chinese n-butanol acetic acid market development trend and prospect forecast report Ⓧ 2022 ~ 2028
Fiori applications are shared through the enhancement of adaptation project
spark源码阅读总纲
CV顶会最佳论文得主分享:好论文是怎么炼成的?
Zabbix 6.0 源码安装以及 HA 配置
3.4 《数据库系统概论》之数据查询—SELECT(单表查询、连接查询、嵌套查询、集合查询、多表查询)
Redis explores cache consistency