[LeetCode-70] Climbing Stairs
2016-04-05 18:05
525 查看
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[C++]:
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Solution[C++]:
class Solution { public: int climbStairs(int n) { if(n==0) return 0; if(n==1) return 1; int amountOfWays[n+1]; amountOfWays[0] = 1; amountOfWays[1] = 1; for(int i = 2; i <= n;i++){ amountOfWays[i] = amountOfWays[i-1] + amountOfWays[i-2]; } return amountOfWays ; } };
相关文章推荐
- C++动态规划之最长公子序列实例
- C++动态规划之背包问题解决方法
- C#使用动态规划解决0-1背包问题实例分析
- 动态规划
- leetcode 179 Largest Number
- leetcode 24 Swap Nodes in Pairs
- leetcode 2 Add Two Numbers 方法1
- leetcode 2 Add Two Numbers 方法2
- C++ 动态规划
- leetcode----Longest Substring Without Repeating Characters
- [LeetCode]47 Permutations II
- [LeetCode]65 Valid Number
- [LeetCode]123 Best Time to Buy and Sell Stock III
- [LeetCode] String Reorder Distance Apart
- [LeetCode] Sliding Window Maximum
- [LeetCode] Find the k-th Smallest Element in the Union of Two Sorted Arrays
- [LeetCode] Determine If Two Rectangles Overlap
- [LeetCode] A Distance Maximizing Problem
- leetcode_linearList
- leetcode_linearList02