[LeetCode] 016: Climbing Stairs
来源:互联网 发布:售楼软件有哪些 编辑:程序博客网 时间:2024/06/17 19:28
[Problem]
[Solution]
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]
class Solution {说明:版权所有,转载请注明出处。Coder007的博客
public:
int climbStairs(int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(n <= 0)return 0;
if(n <= 2)return n;
// n >= 3
int array[n+1];
for(int i = 1 ; i <= n; ++i){
if(i <= 2)
array[i] = i;
else
array[i] = array[i-1] + array[i-2];
}
return array[n];
}
};
阅读全文
0 0
- [LeetCode] 016: Climbing Stairs
- LeetCode: Climbing Stairs
- LeetCode: Climbing Stairs
- [LeetCode]Climbing Stairs
- LeetCode Climbing Stairs
- [Leetcode] Climbing Stairs
- Leetcode: Climbing stairs
- LeetCode Climbing Stairs
- [LeetCode] Climbing Stairs
- leetcode 107: Climbing Stairs
- [LeetCode] Climbing Stairs
- [LeetCode]Climbing Stairs
- [leetcode]Climbing Stairs
- LeetCode-Climbing Stairs
- [leetcode] Climbing Stairs
- LeetCode - Climbing Stairs
- LeetCode:Climbing Stairs
- Leetcode Climbing Stairs
- Input子系统详解
- [LeetCode] 014: Binary Tree Maximum Path Sum
- Oracle中的函数
- [LeetCode] 015: Binary Tree Zigzag Level Order Traversal
- Scrapy——模拟登陆爬取github issues
- [LeetCode] 016: Climbing Stairs
- [LeetCode] 017: Combination Sum
- Tomcat服务器的使用
- [LeetCode] 018: Combination Sum II
- [LeetCode] 019: Combinations
- [LeetCode] 020: Construct Binary Tree from Inorder and Postorder Traversal
- 逆向入门--简单win32CK逆向手记
- [LeetCode] 021: Construct Binary Tree from Preorder and Inorder Traversal
- 最大长方形