博客
关于我
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分库分表中间件简书_MySQL分库分表
查看>>
MySQL分库分表会带来哪些问题?分库分表问题
查看>>
MySQL分组函数
查看>>
MySQL分组查询
查看>>
Mysql分表后同结构不同名称表之间复制数据以及Update语句只更新日期加减不更改时间
查看>>
mySql分页Iimit优化
查看>>
MySQL分页查询
查看>>
WebDriverException:未知错误:对于旧版本的 Google Chrome,在 Python 中找不到带有 Selenium 的 Chrome 二进制错误
查看>>
mysql列转行函数是什么
查看>>