-- coding:utf-8 --
class Solution:
def jumpFloor(self, number):
# write code here
# 动态规划
# p[n]为跳到n级台阶总共的方法数
# p[n] = p[n-2] + p[n-1]
# 初始化:p[1]=1, p[2]=2
# 动态规划的优化空间,数组优化为变量,O(n)优化为O(1)
if number <= 1:
return 1
if number == 2:
return 2
p0 = 1
p1 = 2
for i in range(2, number):
p0, p1 = p1, p0 + p1
return p1