Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
IceTeaz committed Oct 26, 2020
1 parent bd2f1d4 commit 469c832
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 60 additions & 22 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions 动态规划/322. 零钱兑换/main.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package main

func main() {

coinChange([]int{2}, 3)
}

func coinChange(coins []int, amount int) int {
dp := make([][]int, len(coins)+1)
dp := make([]int, amount+1)
dp[0] = 0
for i := 0; i < len(dp); i++ {
for i := 1; i < len(dp); i++ {
dp[i] = amount + 1
for _, coin := range coins {
if i-coin < 0 {
continue
}
dp[i] = min(dp[i], dp[i-coin]+1)
}
}
return dp[amount] == amount+1
if dp[amount] == amount+1 {
return -1
}
return dp[amount]
}

func min(x, y int) int {
Expand Down

0 comments on commit 469c832

Please sign in to comment.