70. Climbing Stairs
2016-02-12 00:37
435 查看
动态规划 最后一步走1步还是两步
public class Solution {
public int climbStairs(int n) {
if(n==1){
return 1;
}
if(n==2){
return 2;
}
int lastlast=1;
int last=2;
int now=0;
for(int i=3;i<=n;i++){
now=last+lastlast;
lastlast=last;
last=now;
}
return now;
}
}
public class Solution {
public int climbStairs(int n) {
if(n==1){
return 1;
}
if(n==2){
return 2;
}
int lastlast=1;
int last=2;
int now=0;
for(int i=3;i<=n;i++){
now=last+lastlast;
lastlast=last;
last=now;
}
return now;
}
}
相关文章推荐
- 2016-02-11 阅读札记: 移动GPU + 多线程 mprotect + AlphaGO的浅析 + SVAIL-cluster
- HDU 1789 Doing Homework again(贪心)
- 172. Factorial Trailing Zeroes LeetCode
- hdu2457 DNA repair(AC自动机+dp)
- HDOJ 1789 Doing Homework again
- git rebase与 git合并(error: failed to push some refs to)解决方法
- UVA 11374 - Airport Express(最短路)
- 51Nod 1305 Pairwise Sum and Divide(规律、数学)
- Linux进程 -- wait/waitpid函数
- 217. Contains Duplicate
- 1106. Lowest Price in Supply Chain (25)
- AIM Tech Round Div 1
- C++ 工程实践(4):二进制兼容性http://blog.csdn.net/Solstice/article/details/6233478
- Light OJ 1086 Jogging Trails (Floyd+状压DP)
- AIM Tech Round (Div. 2)题解
- 1014. Waiting in Line (30)
- 70. Climbing Stairs LeetCode
- Light OJ 1071 Baker Vai (DP)
- 217. Contains Duplicate LeetCode
- Codeforces AIM TECT Round#1 B DP