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?

Note: Given n will be a positive integer.

 

 1 class Solution(object):
 2     def climbStairs(self, n):
 3         """
 4         :type n: int
 5         :rtype: int
 6         """
 7         a = b = 1
 8         for _ in range(n):
 9             a, b = b, a + b
10         return a

a:the number of ways to reach the current step

b: the number of ways to reach the next step

posted on 2017-03-14 19:49  Ci_pea  阅读(98)  评论(0编辑  收藏  举报