diff --git a/problems/0070.爬楼梯完全背包版本.md b/problems/0070.爬楼梯完全背包版本.md index 69750f8f..9fc33bb8 100644 --- a/problems/0070.爬楼梯完全背包版本.md +++ b/problems/0070.爬楼梯完全背包版本.md @@ -149,7 +149,26 @@ Python: 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] +} +```