CoinChange finds the number of possible combinations of coins of different values which can get to the target amount.
(coins []int32, amount int32)
| 9 | // CoinChange finds the number of possible combinations of coins |
| 10 | // of different values which can get to the target amount. |
| 11 | func CoinChange(coins []int32, amount int32) int32 { |
| 12 | combination := make([]int32, amount) |
| 13 | combination[0] = 1 |
| 14 | |
| 15 | for _, c := range coins { |
| 16 | for i := c; i < amount; i++ { |
| 17 | |
| 18 | combination[i] += combination[i-c] |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | return combination[amount-1] |
| 23 | } |
no outgoing calls