52_leetcode_Climbing Stairs
2014-06-19 17:01
288 查看
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?
//easy
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
//easy
int climbStairs(int n) { if(n <= 0) { return 0; } if(n <= 2) { return n; } int first = 1; int second = 2; int result = 0; for(int i = 3; i <= n; i++) { result = first + second; first = second; second = result; } return result; }
相关文章推荐
- [C++]LeetCode: 52 Climbing Stairs
- [LeetCode] Climbing Stairs 爬梯子问题
- leetcode解题方案--070--Climbing Stairs
- [LeetCode] Climbing Stairs, Solution
- LeetCode(52)-Remove Linked List Elements
- 算法设计Week8 LeetCode Algorithms Problem #70 Climbing Stairs
- leetCode(52):Add Binary
- LeetCode题解:Climbing Stairs
- 【Leetcode】Climbing Stairs
- LeetCode 52 Same Tree
- [LeetCode] Climbing Stairs (DP)
- 【Leetcode】Climbing Stairs
- LeetCode Climbing Stairs 爬楼梯
- Leetcode -- Climbing Stairs
- Leetcode 70 Climbing Stairs 爬楼梯的方法(动态规划)
- leetcode_Climbing Stairs
- LeetCode 子 Climbing Stairs
- [leetcode][Climbing Stairs]
- leetcode || 70、 Climbing Stairs
- LeetCode——Climbing Stairs