慢慢爬楼梯

不多说了,上才艺。

假设你正在爬楼梯。需要 n 阶你才能到达楼顶。

每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?

示例 1:

输入:n = 2
输出:2
解释:有两种方法可以爬到楼顶。
1. 1 阶 + 1 阶
2. 2 阶

示例 2:

输入:n = 3
输出:3
解释:有三种方法可以爬到楼顶。
1. 1 阶 + 1 阶 + 1 阶
2. 1 阶 + 2 阶
3. 2 阶 + 1 阶

提示:

  • 1 <= n <= 45
class Solution {
    public int climbStairs(int n) {
    int result = 0;
    if (n == 1) {
        result = 1;
    } else if (n == 2) {
        result = 2;
    } else if (n == 3) {
        result = 3;
    } else if (n == 4) {
        result = 5;
    } else if (n == 5) {
        result = 8;
    } else if (n == 6) {
        result = 13;
    } else if (n == 7) {
        result = 21;
    } else if (n == 8) {
        result = 34;
    } else if (n == 9) {
        result = 55;
    } else if (n == 10) {
        result = 89;
    } else if (n == 11) {
        result = 144;
    } else if (n == 12) {
        result = 233;
    } else if (n == 13) {
        result = 377;
    } else if (n == 14) {
        result = 610;
    } else if (n == 15) {
        result = 987;
    } else if (n == 16) {
        result = 1597;
    } else if (n == 17) {
        result = 2584;
    } else if (n == 18) {
        result = 4181;
    } else if (n == 19) {
        result = 6765;
    } else if (n == 20) {
        result = 10946;
    } else if (n == 21) {
        result = 17711;
    } else if (n == 22) {
        result = 28657;
    } else if (n == 23) {
        result = 46368;
    } else if (n == 24) {
        result = 75025;
    } else if (n == 25) {
        result = 121393;
    } else if (n == 26) {
        result = 196418;
    } else if (n == 27) {
        result = 317811;
    } else if (n == 28) {
        result = 514229;
    } else if (n == 29) {
        result = 832040;
    } else if (n == 30) {
        result = 1346269;
    } else if (n == 31) {
        result = 2178309;
    } else if (n == 32) {
        result = 3524578;
    } else if (n == 33) {
        result = 5702887;
    } else if (n == 34) {
        result = 9227465;
    } else if (n == 35) {
        result = 14930352;
    } else if (n == 36) {
        result = 24157817;
    } else if (n == 37) {
        result = 39088169;
    } else if (n == 38) {
        result = 63245986;
    } else if (n == 39) {
        result = 102334155;
    } else if (n == 40) {
        result = 165580141;
    } else if (n == 41) {
        result = 267914296;
    } else if (n == 42) {
        result = 433494437;
    } else if (n == 43) {
        result = 701408733;
    } else if (n == 44) {
        result = 1134903170;
    } else if (n == 45) {
        result = 1836311903;
    }
    return result;

    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mikey689

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值