We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 7e18c10 + 1702f40 commit 9846b55Copy full SHA for 9846b55
go/0518-coin-change-2.go
@@ -0,0 +1,23 @@
1
+func change(amount int, coins []int) int {
2
+
3
+ row := make([]int, amount+1)
4
+ row[0] = 1
5
6
+ for i := len(coins) - 1; i >= 0; i-- {
7
8
+ nextRow := make([]int, amount+1)
9
+ nextRow[0] = 1
10
11
+ for a := 1; a < amount+1; a++ {
12
+ nextRow[a] = row[a]
13
+ if a-coins[i] >= 0 {
14
+ nextRow[a] += nextRow[a-coins[i]]
15
+ }
16
17
18
+ row = nextRow
19
20
21
+ return row[amount]
22
+}
23
0 commit comments