leetcode--Climbing Stairs
2015-06-05 13:54
369 查看
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?public class Solution {
public int climbStairs(int n) {
if(n==1) return 1;
int[] res = new int[2];
res[0] = 1;
res[1] = 2;
while(n>2){
int t = res[1];
res[1] += res[0];
res[0] = t;
n--;
}
return res[1];
}
}
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 1;
int[] res = new int[2];
res[0] = 1;
res[1] = 2;
while(n>2){
int t = res[1];
res[1] += res[0];
res[0] = t;
n--;
}
return res[1];
}
}
相关文章推荐
- 修复 FLASHMAIL 只能发不能收的问题
- JetBrain WebStorm 注册码
- 数据挖掘十大经典算法(9) 朴素贝叶斯分类器 Naive Bayes
- SVN show log failed
- 德州扑克AI简介——2015华为软件精英赛小结
- Contains Duplicate III
- 进程控制 [fork() exec() wait() waitpid()]
- 强人工智能基本问题:全局控制与自组织
- SharePoint 2013上传AI格式文件,再次下载后变成了PS格式文件
- leetcode_70题——Climbing Stairs(简单DP题)
- 11. Container With Most Water
- Naive Bayes在mapreduce上的实现
- leetcode 217: Contains Duplicate
- 正确使用Block避免Cycle Retain和Crash
- LeetCode "Contains Duplicate III"
- sgu252:Railway Communication(费用流)
- Climbing Stairs
- 从main函数中argc和argv开始学习
- [LOJ 1038] Race to 1 Again
- How did your survive waiting