源码之家

  • 首页
  • 文章
  • 问答
  • 下载
您的位置: 首页  >  文章  >  [leetcode]Climbing Stairs 爬楼梯

[leetcode]Climbing Stairs 爬楼梯

分类: 文章 • 2024-09-24 11:50:34

[leetcode]Climbing Stairs 爬楼梯

[leetcode]Climbing Stairs 爬楼梯 

 
    int climbStairs(int n) {
       if (n == 1)
            return 1;
        else if (n == 2)
            return 2;
        else {
            int stairs[n];
            stairs[0] = 1;
            stairs[1] = 2;
            for(int i=2;i<n;i++) {
                stairs[i]=stairs[i-1]+stairs[i-2];
            }
            return stairs[n-1];
        }
    }

 

相关推荐

  • 746. Min Cost Climbing Stairs 有问题
  • 【Leetcode】746. Min Cost Climbing Stairs
  • 【leetcode】爬楼梯(@lru_cache()装饰器用法)
  • leetcode-746. 使用最小花费爬楼梯
  • leetcode746. 使用最小花费爬楼梯
  • Leetcode 简单十八 爬楼梯
  • LeetCode70-爬楼梯-Python3-两种方法
  • LeetCode 746. 使用最小花费爬楼梯,多解法实现(穷举、递归、动态规划)
  • 【Leetcode】70. Climbing Stairs
  • 【LeetCode】70. Climbing Stairs
  • 递归-八皇后问题(回溯算法)
  • Centos7部署YUM仓库及NFS共享服务(一)
    网站免责声明 网站地图 最新文章 用户隐私 版权申明
本站所有数据收集于网络,如果侵犯到您的权益,请联系网站进行下架处理。   

Copyright © 2018-2021   Powered By 源码之家    备案号:   粤ICP备20058927号