题目:
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
思路:动态规划,n可以看做前n-1步的解法*1(再走1step)+前n-2步的解法*1(再走2step)
class Solution(object):
def climbStairs(self, n):"""
:type n: int
:rtype: int
"""
if n==1:return 1
if n==2:return 2
ll=1;l=2
if n>2:
i=3
while i<=n:
ll=ll+l;ll,l=l,ll
i+=1
return l