deno.land / x / masx200_leetcode_test@10.6.5 / coin-change / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
export default function coinChange(coins: number[], amount: number): number { if (amount === 0) return 0; const dp = new Array(amount + 1).fill(Infinity); dp[0] = 0; for (let i = 1; i <= amount; i++) { for (const c of coins) { if (i - c >= 0) { dp[i] = Math.min(dp[i], dp[i - c] + 1); } } } return Number.isFinite(dp[amount]) ? dp[amount] : -1;}
masx200_leetcode_test

Version Info

Tagged at
a year ago