LeetCode 算法题解与代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public int coinChange(int[] coins, int amount) {
int len = coins.length;
int[][] f = new int[len + 1][amount + 1];
Arrays.fill(f[0], Integer.MAX_VALUE / 2);
f[0][0] = 0;
for (int i = 0; i < len; i++) {
for (int j = 0; j <= amount; j++) {
if (j < coins[i])
f[i+1][j] = f[i][j];
else
f[i+1][j] = Math.min(f[i+1][j-coins[i]] + 1, f[i][j]);
}
}
return f[len][amount] >= Integer.MAX_VALUE / 2 ? -1 : f[len][amount];
}
}

Comments
Recent Posts
Untitled
Categories
Tags
Website Info
Article Count :
2
Total Word Count :
1.6k
Unique Visitors :
Page Views :
Last Update :