网址:https://leetcode.com/problems/climbing-stairs/

其实就是斐波那契数列,没什么好说的。

注意使用3个变量,而不是数组,可以节约空间。

 class Solution {
public:
int climbStairs(int n) {
if(n<=)
return n;
int a, b = , c = ;
for(int i=;i<=n;i++)
{
a = b + c;
c = b;
b = a;
}
return a;
}
};

70. Climbing Stairs爬楼梯的更多相关文章

  1. [LeetCode] 70. Climbing Stairs 爬楼梯问题

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  2. [LeetCode] 70. Climbing Stairs 爬楼梯

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  3. LeetCode 70. Climbing Stairs爬楼梯 (C++)

    题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either cl ...

  4. [leetcode]70. Climbing Stairs爬楼梯

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  5. Leetcode 70. Climbing Stairs 爬楼梯 (递归,记忆化,动态规划)

    题目描述 要爬N阶楼梯,每次你可以走一阶或者两阶,问到N阶有多少种走法 测试样例 Input: 2 Output: 2 Explanation: 到第二阶有2种走法 1. 1 步 + 1 步 2. 2 ...

  6. [LeetCode] Min Cost Climbing Stairs 爬楼梯的最小损失

    On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...

  7. climbing stairs(爬楼梯)(动态规划)

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  8. [LeetCode] 746. Min Cost Climbing Stairs 爬楼梯的最小损失

    On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...

  9. Climbing Stairs爬楼梯——动态规划

    题目描写叙述: 初阶:有n层的台阶,一開始你站在第0层,每次能够爬两层或者一层. 请问爬到第n层有多少种不同的方法? 进阶:假设每次能够爬两层.和倒退一层,同一个位置不能反复走,请问爬到第n层有多少种 ...

随机推荐

  1. powerdesigner反转数据库的设计图

    PowerDesigner导入sql文件 1:点击 2:弹出该页面,点击确定 3:弹出一下页面,点击下面按钮选择文件 4:点击确定完成 二 .表转换为中文的执行脚本及步骤 执行脚本为:Option E ...

  2. 网页中动态嵌入PDF文件/在线预览PDF内容https://www.cnblogs.com/xgyy/p/6119459.html

    #网页中动态嵌入PDF文件/在线预览PDF内容# 摘要:在web开发时我们有时会需要在线预览PDF内容,在线嵌入pdf文件: 问题1:如何网页中嵌入PDF: 在网页中: 常用的几种PDF预览代码片段如 ...

  3. 【译】第24节---Fluent API - 属性映射

    原文:http://www.entityframeworktutorial.net/code-first/configure-property-mappings-using-fluent-api.as ...

  4. SAP 财务模块 FI-TV 差旅管理

    SAP 财务模块 FI-TV 差旅管理 Travel Management差旅管理事务码              描述PRT3      Trip Costs: Maintain Postings ...

  5. R语言可视化学习笔记之ggpubr包—SCI文章图

    转载:https://www.jianshu.com/p/678213d605a5?from=jiantop.com Hadley Wickham创建的可视化包ggplot2可以流畅地进行优美的可视化 ...

  6. CentOS7 下curl使用

    curl工具工具的主页:https://curl.haxx.se/NAMEcurl - transfer a URL SYNOPSIScurl [options] [URL...] DESCRIPTI ...

  7. 在SQL Server 2018 Management Studio中修改表字段顺序

    有时我们可能需要为一个已存在的数据库表添加字段,并且想让这个字段默认排的靠前一些,这时就需要为表字段重新进行排序,默认情况下在Management Studio中调整顺序并保存时会提示“不允许保存更改 ...

  8. <script src="../build/browser.min.js"></script> 是用来里面babel工具把ES6的语法转成ES5

    <!DOCTYPE html> <html> <head> <script src="../build/react.js">< ...

  9. leecode第八十八题(合并两个有序数组)

    class Solution { public: void merge(vector<int>& nums1, int m, vector<int>& nums ...

  10. SublimeText3按ctrl+b执行python无反应

    现象:在Sublime中打开.py文件,按”ctrl+b”执行时无反应.点击工具->编译系统中已经有且识别到Python,但执行”run(ctrl+shift+b)”时无反应,Sublime左下 ...