###### [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 or 2 steps. In how many distinct ways can you climb to the top?

Solution 1

idea: recursive function, however, run out of limit time

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

Solution 2

idea: similar to Fibonacci number

class Solution {
public:
int climbStairs(int n) {
if (n==1)
return 1;
else if (n==2)
return 2;
else{
int ppre = 1;
int pre = 2;
for (int i = 3; i < n; i++){
int tmp = pre;
pre = ppre+pre;
ppre = tmp;
}
return pre+ppre;
}

}
};

#### leetcode之70. Climbing Stairs(C++解法 动态规划思想)

2016-09-21 15:19:49

#### leetcode 70 Climbing Stairs

2015-04-29 17:46:09

#### LeetCode（70） Climbing Stairs

2015-08-19 21:54:20

#### LeetCode 70 Climbing Stairs(Python详解及实现)

2017-08-05 12:56:00

#### (Java)LeetCode-70. Climbing Stairs

2016-11-06 16:01:21

#### LeetCode 70 — Climbing Stairs（C++ Java Python）

2014-03-20 22:17:03

#### leetcode 70.Climbing Stairs-爬楼梯|动态规划

2015-10-07 13:00:01

#### 70. Climbing Stairs [easy] (Python)

2016-05-26 13:10:58

#### LeetCode-70-Climbing Stairs(动态规划)-Easy

2016-03-19 13:17:05

#### [70] Climbing Stairs

2016-07-20 23:24:52

## 不良信息举报

[leetcode] 70. Climbing Stairs