题解 | #跳台阶#
跳台阶
http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
# 动态规划
class Solution:
def jumpFloor(self , number: int) -> int:
# write code here
dp = [0 for _ in range(number+1)] # dp[i] 表示跳上第i个台阶的总跳法
dp[0], dp[1] = 1, 1 # 初始化
for i in range(2, number+1):
dp[i] = dp[i-1] + dp[i-2]
return dp[number]