70. Climbing Stairs
2016-01-19 20:22
357 查看
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?
典型的动态规划问题
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
典型的动态规划问题
public class Solution { public int climbStairs(int n) { if (n < 1) return 0; if (n == 1) return 1; int oneStep = 1, twoStep = 0; for (int i = 1; i <= n; i++) { int t = oneStep+twoStep; twoStep = oneStep; oneStep = t; } return oneStep; } }
相关文章推荐
- Codeforces 196 C. Paint Tree
- Debug Assertion Failed! Expression: _pFirstBlock == pHead
- hadoop下运行mapreduce程序Failed to set permissions of path:的解决
- FTP error : 451 Failure writing to local file
- 生产者消费者例子-采用wait()和notify()
- Command /usr/bin/codesign failed with exit code 1
- What floating point types are available in .NET?
- Could not find the main class:
- adi_osal_Init_failure
- main函数传参数以及执行过程
- usb mode waiting
- 解决TIME_WAIT过多的方法
- 【rabbitmq】error XX/otp_src_18.2.1/erts/configure' failed for erts
- Paint及Canvas的简单应用等【转】
- 基于Gabor特征提取和人工智能神经网络的人脸检测matlab代码
- Parameter not found.Available parameters are [0, 1, 2, param3, param1, param2]
- EF报LINQ to Entities 不识别方法“Web_JZRepository.Models.copy_materials_details get_Item(Int32) ”,因此该方法无法转换为存储表达式。
- maven打包jar指定 Main-Class
- zoj 1239 Hanoi Tower Troubles Again!
- 550 Create directory operation failed