# Des

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?

# 分析

## 递归法：

class Solution {
public:
int climbStairs(int n) {
if(n==1) return 1;
if(n==2) return 2;
return climbStairs(n-1)+climbStairs(n-2);
}
};

# Code

class Solution {
public:
int climbStairs(int n) {
int a=0;
int b=1;
int sum=0;
for(int i=1;i<=n;i++){
sum=a+b;
a=b;
b=sum;
}
return sum;
}
};

• 本文已收录于以下专栏：

## 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 70 Climbing Stairs（爬楼梯）（动态规划）（*）

• NoMasp
• 2016-01-14 07:12
• 4055

## [LeetCode]70.Climbing Stairs

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

## 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 Java版 （青蛙跳台阶）

leetcode解题之70 #Climbing Stairs Java版 （青蛙跳台阶）

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)