题解 | #跳台阶#
跳台阶
http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
package main /* //动态规划,时间On,空间On func jumpFloor(number int ) int { dp := make([]int, number+1) dp[0], dp[1] = 1, 1 for i := 2; i < len(dp); i++ { dp[i] = dp[i-1] + dp[i-2] } return dp[number] } */ //记忆化搜索,空间压缩为O1 func jumpFloor(number int) int { prev , cur := 1, 1 for i := 2; i < number+1; i++ { temp := cur cur = prev + cur prev = temp } return cur }