LeetCode:Climbing Stairs
来源:互联网 发布:diy制作软件 编辑:程序博客网 时间:2024/05/02 15:02
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?
这题是求斐波那契数列。
我起初没意识到是斐波那契数列,其实用动态规划的思想也可以做。
package leetcode;public class ClimbingStairs {public static void main(String[] args) {System.out.println(new ClimbingStairs().climbStairs(7));} public int climbStairs(int n) {if (n == 0) {return 0;}if (n == 1) {return 1;}if (n == 2) {return 2;}int[] result = new int[3];result[2] = 1;result[1] = 2;for (int i = 0; i < n - 2; i++) {result[0] = result[1] + result[2];result[2] = result[1];result[1] = result[0];}return result[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
- Java集合类详解
- Android项目实战--手机卫士06--GridView的优化与修改Button的显示样式
- Oracle 闪回特性(FLASHBACK DATABASE)
- 上传下载和文件操作
- Fiddler HTTP调试代理
- LeetCode:Climbing Stairs
- Linux 下 OpenCV 2.4.6.1编译配置
- 服务器清除登录密码
- 类别
- MarioTCP:一个可单机支持千万并发连接的TCP服务器
- hdu 4287( PHONE LIST)
- Oracle 实例恢复
- 根据年月获取本月的最后一天
- sqlserver关于错误“ provider: TCP 提供程序, error: 40 - 由于目标机器积极拒绝,无法连接”的解决