博客
关于我
322. 零钱兑换
阅读量:521 次
发布时间:2019-03-07

本文共 496 字,大约阅读时间需要 1 分钟。

class Solution {    public int coinChange(int[] coins, int amount) {        if(amount==0) return 0;		if (coins == null || coins.length == 0) return -1;		int[] dp = new int[amount + 1];		for (int i = 1; i <= amount; i++) {			int min = Integer.MAX_VALUE;			for (int face : coins) {				if (i < face) continue;				int v = dp[i - face];				if (v < 0 || v >= min) continue;				min = v;			}			if (min == Integer.MAX_VALUE) {				dp[i] = -1;			} else {				dp[i] = min + 1;			}		}		return dp[amount];    }}

转载地址:http://moznz.baihongyu.com/

你可能感兴趣的文章
Node-RED中配置周期性执行、指定时间阶段执行、指定时间执行事件
查看>>
Node-RED安装图形化节点dashboard实现订阅mqtt主题并在仪表盘中显示温度
查看>>
Node-RED怎样导出导入流程为json文件
查看>>
Node-RED简介与Windows上安装、启动和运行示例
查看>>
Node-RED订阅MQTT主题并调试数据
查看>>
Node-RED通过npm安装的方式对应卸载
查看>>
node-request模块
查看>>
node-static 任意文件读取漏洞复现(CVE-2023-26111)
查看>>
Node.js 8 中的 util.promisify的详解
查看>>