[Leetcode]-Climbing Stairs
来源:互联网 发布:网络代理合作协议 编辑:程序博客网 时间:2024/05/21 05:19
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?
Hide Tags: Dynamic Programming
题目:爬楼梯,需要爬到第N步,每次你可以爬层2步或者1步,问总共有几种方法?
思路:Dynamic Programming(动态规划)
//DP(Dynamic Programming) algorithms 见算法导论//S[n] = S[n-1] + S[n-2] ; //S[1] = 1 ;//S[2] = 2 ;int climbStairs(int n) { if( n == 0) return 0; if( n == 1) return 1; if( n == 2) return 2; int one_step = 1; int two_step = 2; int sum_ways = 0; int i = 0 ; for(i=2;i<n;i++) { sum_ways = one_step + two_step; one_step = two_step; two_step = sum_ways; } return sum_ways;}
0 0
- 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
- LeetCode | Climbing Stairs
- flex 4横向带图下拉列表和联动下拉列表
- Installation error: INSTALL_FAILED_UID_CHANGED解决办法总结
- Java基础日记———Map
- MySQL的配置选项
- 如何将NTFS For Mac手动激活
- [Leetcode]-Climbing Stairs
- Android API Level与sdk版本对照表
- 关于053 第66题
- mysql 5.5 卸载
- css中的颜色及长度
- springMVC学习笔记-后端给前端·传递数据
- 《Fisher Kernels on Visual Vocabularies for Image Categorization》学习笔记
- 如何禁用Mac防火墙激活软件
- 配置Mahout——ubuntu安装Eclipse最新版