mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
添加0070.爬楼梯完全背包版本 Go版本
This commit is contained in:
@ -149,7 +149,26 @@ Python:
|
|||||||
|
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
```go
|
||||||
|
func climbStairs(n int) int {
|
||||||
|
//定义
|
||||||
|
dp := make([]int, n+1)
|
||||||
|
//初始化
|
||||||
|
dp[0] = 1
|
||||||
|
// 本题物品只有两个1,2
|
||||||
|
m := 2
|
||||||
|
// 遍历顺序
|
||||||
|
for j := 1; j <= n; j++ { //先遍历背包
|
||||||
|
for i := 1; i <= m; i++ { //再遍历物品
|
||||||
|
if j >= i {
|
||||||
|
dp[j] += dp[j-i]
|
||||||
|
}
|
||||||
|
//fmt.Println(dp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dp[n]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user