# [LeetCode] 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?

Show Tags

这题其实就是斐波那契数列来的。

```#include <iostream>
using namespace std;

class Solution {
public:
int climbStairs(int n) {
if(n<2) return 1;
int l=1,r=1,tmp;
for(int i=2;i<=n;i++){
tmp=l+r;
l=r;
r=tmp;
}
return r;
}
};

int main()
{
Solution sol;
for(int i =0;i<9;i++)
cout<<sol.climbStairs(i)<<endl;
return 0;
}```

## 70. 爬梯子问题（斐波那契数列）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阶,你有两种爬法,每次爬一阶或者两阶.请问你有多少种爬法到达楼梯顶部. public int ClimbStairs(int n) { i

## LeetCode | 面试题10- I. 斐波那契数列【剑指Offer】【Python】

LeetCode 面试题10- I. 斐波那契数列[剑指Offer][Easy][Python][动态规划] 问题 力扣 写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项.斐波那契数列的定义如下: F(0) = 0, F(1) = 1 F(N) = F(N - 1) + F(N - 2), 其中 N > 1. 斐波那契数列由 0 和 1 开始,之后的斐波那契数就是由之前的两数相加而得出. 答案需要取模 1e9+7(1000000007),如计算初始结果为:10000000

## 斐波那契数列 Library

http://acm.tju.edu.cn/toj/showp3267.html3267.   Library Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 214   Accepted Runs: 96 Description As we all know, there are very long stairs before our library in campus III of our school. It is so

## Fibonacci斐波拉契数列----------动态规划DP

n==10 20 30 40 50 46 体验一下,感受一下,运行时间 #include <stdio.h>int fib(int n){ if (n<=1)     return 1; else            return fib(n-1)+fib(n-2); }int main( ){ int n; scanf("%d",&n); printf("%d\n" ,fib(n) );} 先 n==10 20 30 40 50 46