博客
关于我
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错误:This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de
查看>>
mysql长事务
查看>>
mysql问题记录
查看>>
mysql间隙锁
查看>>
MySQL集群解决方案(1):MySQL数据库的集群方案
查看>>
MySQL集群解决方案(2):主从复制架构
查看>>
MySQL集群解决方案(3):MyCat中间件
查看>>
MySQL集群解决方案(4):负载均衡
查看>>
MySQL集群解决方案(5):PXC集群
查看>>