Climbing Stairs

原创 2015年07月08日 17:22:31

class Solution {
public:
    int climbStairs(int n) {
        //其实是斐波那契数列的变形问题,f(n) = f(n-1) + f(n-2)
        int last1 = 1, last2 = 1;//f0 = 1, f1 = 1
        int result = 1;
        for(int i = 2;i<=n;i++)
        {
            result = last1 + last2;
            last1 = last2;
            last2 = result;
        }
        
        return result;
    }
};


版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

leetcode Climbing Stairs

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

【LeetCode-面试算法经典-Java实现】【073-Climbing Stairs(爬楼梯)】

【070-Climbing Stairs(爬楼梯)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  You are climbing a stair case. It ta...

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

LeetCode 之 Climbing Stairs (方法2)

上一次说了自顶向下,没看的可以回去看看 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 1...

Leetcode note--Leetcode 70climbing Stairs

70. Climbing Stairs  My Submissions Total Accepted: 143040Total Submissions: 37227...

LeetCode 70 Climbing Stairs(爬楼梯)(动态规划)(*)

翻译你正在爬一个楼梯。它需要n步才能到底顶部。每次你可以爬1步或者2两步。那么你有多少种不同的方法爬到顶部呢?原文You are climbing a stair case. It takes n s...
  • NoMasp
  • NoMasp
  • 2016-01-14 07:12
  • 3862

Climbing Stairs爬楼梯啊爬楼梯(支持n step)

leetcode原题 You are climbing a stair case. It takes n steps to reach to the top. Each time you ...

[LeetCode]70.Climbing Stairs

【题目】 You are climbing a stair case. It takes n steps to reach to the top. Each time you can eithe...

Climbing Stairs

题目地址:https://leetcode.com/problems/climbing-stairs/You are climbing a stair case. It takes n steps t...

leetcode解题之70 #Climbing Stairs Java版 (青蛙跳台阶)

leetcode解题之70 #Climbing Stairs Java版 (青蛙跳台阶)
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)