Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1941 from kkr2/feat/0518-coin-change-2.go
Browse files Browse the repository at this point in the history
Create 0518-coin-change-2.go
  • Loading branch information
tahsintunan authored Jan 8, 2023
2 parents 7e18c10 + 1702f40 commit 9846b55
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions go/0518-coin-change-2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
func change(amount int, coins []int) int {

row := make([]int, amount+1)
row[0] = 1

for i := len(coins) - 1; i >= 0; i-- {

nextRow := make([]int, amount+1)
nextRow[0] = 1

for a := 1; a < amount+1; a++ {
nextRow[a] = row[a]
if a-coins[i] >= 0 {
nextRow[a] += nextRow[a-coins[i]]
}
}

row = nextRow
}

return row[amount]
}

0 comments on commit 9846b55

Please sign in to comment.