题目链接
https://leetcode.com/problems/climbing-stairs/
题目原文
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阶。每次你可以爬1或2阶楼梯,你有多少种不同的爬法可以到顶?
思路方法
思路一
比较直观的思路,对于输入的n,我们可以跨 i=1, 2, 3, …, n/2 个两步台阶。对于这 n/2 种情况,每种情况需要跨 n-i 次,所以每种情况又有 C(n-i, i) 种不同的跨法。计算比较复杂。
代码
class Solution(object):
def climbStairs