当前位置:网站首页>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 周五了,今天是个承上启下的日子
边栏推荐
- Professor Li Zexiang, Hong Kong University of science and technology: I'm wrong. Why is engineering consciousness more important than the best university?
- Yarn restart applications record recovery
- Feign & Eureka & Zuul & Hystrix 流程
- 内容审计技术
- Report on the current situation and development trend of bidirectional polypropylene composite film industry in the world and China Ⓟ 2022 ~ 2028
- Apache-atlas-2.2.0 independent compilation and deployment
- 9. Use of better scroll and ref
- 10. Page layout, guess you like it
- VM virtual machine configuration dynamic IP and static IP access
- 1. Sum of two numbers: given an integer array num and an integer target value, please find the two integers whose sum is the target value target in the array and return their array subscripts
猜你喜欢

ZABBIX 6.0 source code installation and ha configuration

流量管理技术

香港科技大学李泽湘教授:我错了,为什么工程意识比上最好的大学都重要?

Fiori applications are shared through the enhancement of adaptation project

【牛客刷题-SQL大厂面试真题】NO2.用户增长场景(某度信息流)

1553B environment construction

codeforces -- 4B. Before an Exam

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

ROS2 Foxy depthai_ ROS tutorial
基于mysql乐观锁实现秒杀的示例代码
随机推荐
Example code of second kill based on MySQL optimistic lock
The 14th five year plan of China's environmental protection industry and the report on the long-term goals for 2035 Ⓖ 2022 ~ 2028
Sharing with the best paper winner of CV Summit: how is a good paper refined?
受益互联网出海 汇量科技业绩重回高增长
Investment analysis and prospect prediction report of global and Chinese p-nitrotoluene industry Ⓙ 2022 ~ 2027
Content Audit Technology
机器学习—性能度量
Report on the "14th five year plan" and investment strategy recommendations for China's industrial robot industry 2022 ~ 2028
Analysis report on the development prospect and investment strategy of the global and Chinese laser chip industry Ⓑ 2022 ~ 2027
流量管理技术
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?
软件测试中功能测试流程
JS discolored Lego building blocks
Redis exploration: cache breakdown, cache avalanche, cache penetration
啟動solr報錯The stack size specified is too small,Specify at least 328k
Three questions about scientific entrepreneurship: timing, pain points and important decisions
When Sqlalchemy deletes records with foreign key constraints, the foreign key constraints do not work. What is the solution?
nexus搭建npm依赖私库
【机器学习】VAE变分自编码器学习笔记
The future of game guild in decentralized games