leetcode 台阶问题
2013-05-10 22:47
253 查看
斐波那契数列的变形,用递归会过不了large judge。所以采用另外一种方法。
class Solution { public: int climbStairs(int n) { if(n==0)return 1; if(n==1)return 1; int a=1; int b=1; int c; for(int i=2;i<=n;i++) { c=a+b; a=b; b=c; } return c; } };
相关文章推荐
- leetcode 746. Min Cost Climbing Stairs 走台阶问题 + 斐波拉契序列 + 动态规划DP
- [LeetCode] Invert Binary Tree - 二叉树翻转系列问题
- leetcode之Find the Duplicate Number 问题
- Leetcode 22, 77: 回溯问题
- Leetcode22.+Leetcode216. 回溯法之应用(二):圆括号+组合问题
- leetCode全字符问题Java版
- leetcode笔记:Maximum Subarray(最大子串和问题)
- Python实现N阶台阶的走法问题
- Leetcode之Valid Palindrome 问题
- LeetCode—*Spiral Matrix问题,主要是用到了方向矩阵,很创意
- Leetcode问题解答:3. Longest Substring Without Repeating Characters
- 青蛙跳台阶的问题
- leetcode中第一题twosum问题解答算法的可行性证明
- Leetcode之Max Consecutive Ones 问题
- N-Queens N皇后问题@LeetCode
- 【LeetCode】加油站问题 gas station
- 使用C++递归求解跳台阶问题
- LeetCode-134. Gas Station(JAVA)加气站问题
- 青蛙跳台阶问题——剑指offer
- [leetcode] min stack问题