大佬题解
⏰ 时间复杂度: O ( n ) O(n) O(n)
class Solution {
public int coinChange(int[] coins, int amount)
{
int INF = 0x3f3f3f3f;
int n = amount;
int[] f = new int[n + 1];
Arrays.fill(f, INF);
f[0] = 0;
for (int i = 0; i < coins.length; i++)
{
int x = coins[i];
for (int j = x; j <= n; j++)
f[j] = Math.min(f[j], f[j - x] + 1);
}
if(f[n] == INF)
return -1;
return f[n];
}
}