70. Climbing Stairs

原创 2016年06月01日 18:42:40

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?

public class Solution {
    public int climbStairs(int n) {
        if (n == 0 || n == 1)
      return 1;
    int pre = 1;
    int current = 1;
    for (int i = 2; i <= n; i++) {
      int temp = current + pre;
      pre = current;
      current = temp;
    }
    return current;
    }
}

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

相关文章推荐

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
  • 4042

[LeetCode]70.Climbing Stairs

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

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...

LeetCode【70】Climbing Stairs

根据题目找规律,见下表策略选择          分析:斐波那契数列的变形           1 1 2 3 5 8 ……        ...

LeetCode70. 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】No.70 Climbing Stairs

【原题】 Given an array of integers, find two numbers such that they add up to a specific target number...

Leetcode刷题记——70. Climbing Stairs(爬楼梯)

一、题目叙述: You are climbing a stair case. It takes n steps to reach to the top. Each time...

Leetcode_70_Climbing Stairs

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41851705 You are climbing a st...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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