mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
update0322.零钱兑换 Go版本
This commit is contained in:
@ -226,11 +226,11 @@ func coinChange1(coins []int, amount int) int {
|
|||||||
for i := 0; i < len(coins); i++ {
|
for i := 0; i < len(coins); i++ {
|
||||||
// 遍历背包
|
// 遍历背包
|
||||||
for j := coins[i]; j <= amount; j++ {
|
for j := coins[i]; j <= amount; j++ {
|
||||||
//if dp[j-coins[i]] != math.MaxInt32 {
|
if dp[j-coins[i]] != math.MaxInt32 {
|
||||||
// 推导公式
|
// 推导公式
|
||||||
dp[j] = min(dp[j], dp[j-coins[i]]+1)
|
dp[j] = min(dp[j], dp[j-coins[i]]+1)
|
||||||
fmt.Println(dp,j,i)
|
//fmt.Println(dp,j,i)
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 没找到能装满背包的, 就返回-1
|
// 没找到能装满背包的, 就返回-1
|
||||||
|
Reference in New Issue
Block a user