[勇者闯LeetCode] 70. Climbing Stairs
2017-03-26 15:36
369 查看
[勇者闯LeetCode] 70. Climbing Stairs
Description
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?
Note: Given n will be a positive integer.
Information
Tags: Dynamic ProgrammingDifficulty: Easy
Solution
实质上是Fibonacci Number:Fib(n)=Fib(n−1)+Fib(n−2),Fib(1)=1,Fib(2)=2,
即爬到n阶的方法数等于爬到n-1阶的方法数和爬到n-2阶的方法数之和,爬到1阶的方法数是1,爬到2阶的方法数是2。
class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int """ prev, cur = 0, 1 for i in range(n): prev, cur = cur, cur + prev return cur
相关文章推荐
- Leetcode 70. Climbing Stairs
- [Leetcode]@python 70. Climbing Stairs
- Leetcode刷题记——70. Climbing Stairs(爬楼梯)
- Leetcode ☞ 70. Climbing Stairs
- leetcode 每日一题 70. Climbing Stairs
- [LeetCode]problem 70. Climbing Stairs
- 【算法作业11】LeetCode 70. Climbing Stairs
- LeetCode 70. Climbing Stairs
- 【C++】【LeetCode】70. Climbing Stairs
- LeetCode 70. Climbing Stairs
- leetcode 70. Climbing Stairs
- Leetcode 70. Climbing Stairs (Easy) (cpp)
- 【LeetCode】70. Climbing Stairs
- LeetCode 70. Climbing Stairs (Python)
- LeetCode笔记:70. Climbing Stairs
- leetcode-70. Climbing Stairs
- [leetcode]70. Climbing Stairs(Java)
- [LeetCode]70. Climbing Stairs
- LeetCode 70. Climbing Stairs
- LeetCode 70. Climbing Stairs(爬楼梯)