博客
关于我
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/

你可能感兴趣的文章
mysql时间相减的问题
查看>>
mysql时间表示和计算
查看>>
MySQL是如何做容器测试的?
查看>>
mysql更改数据库表utf-8_修改mysql数据库为 utf-8
查看>>
mysql更改表引擎INNODB为MyISAM的方法总结
查看>>
mysql更新一个表里的字段等于另一个表某字段的值
查看>>
Mysql更新时间列只改日期为指定日期不更改时间
查看>>
MySQL更新锁(for update)摘要
查看>>
mysql更新频率_MySQL优化之如何了解SQL的执行频率
查看>>
mysql替换表的字段里面内容
查看>>
MySQL最多能有多少连接
查看>>
MySQL最大建议行数 2000w,靠谱吗?
查看>>
MySQL有哪些锁
查看>>
MySQL服务器安装(Linux)
查看>>
mysql服务器查询慢原因分析方法
查看>>
mysql服务无法启动的问题
查看>>
MySQL杂谈
查看>>
mysql权限
查看>>
mysql条件查询
查看>>
MySQL条件查询
查看>>