class Solution:
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
# 递归 time limit
# if n==1 or n==2:
# return n
# return Solution.climbStairs(self,n-1)+Solution.climbStairs(self,n-2)
## 备忘录算法 time limit
# data={}
# if n==1 or n==2:
# return n
# if n in data:
# return data['n']
# else:
# value=Solution.climbStairs(self,n-1)+Solution.climbStairs(self,n-2)
# data['n']=value
# return value
## 动态规划
if n==1 or n==2:
return n
first=1
second=2
temp=0
for i in range(n-2):
temp=first+second
first=second
second=temp
return temp