[LeetCode]Climbing Stairs
2015-08-23 00:49
399 查看
Climbing Stairs 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?
基础的DP,到达n的方法等于到达n-1的方法加上n-2的方法
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?
基础的DP,到达n的方法等于到达n-1的方法加上n-2的方法
class Solution { public: int climbStairs(int n) { int n1=1,n2=1; int all; int i = 2; if(n<2) return 1; while(i<=n){ all = n1 + n2; n2 = n1; n1 = all; ++i; } return all; } };
相关文章推荐
- go get报错 error: RPC failed; result=56, HTTP code =
- Aizu - 2564 Tree Reconstruction 并查集
- POJ2010--Moo University-Financial Aid(二分)
- JPA的PAI测试
- Aizu - 2555 Everlasting Zero 模拟
- hdoj 1022 Train problem 1【栈 的理解】
- 调用Process.waitfor导致的进程挂起
- sleep() wait() yeild()三者之间的区别?
- hdu 1239 Calling Extraterrestrial Intelligence Again
- Debug Assertion Failed! File: afx.inl
- PAT 1014. Waiting in Line (30)
- unresolved external symbol _winmain@16
- rails yaml with expression or variable (Using ERB in YAML Configuration File)
- 【LeetCode】(70)Climbing Stairs (Easy)
- POJ 1995 Raising Modulo Numbers【快速幂】
- CodeForcesGym 100676G Training Camp
- HN OJ 13375 Flowery Trails (spfa的路径遍历)
- Aizu 2302 On or Off
- poj1363——Rails
- 转:CDC,CPaintDC,CClientDC,CWindowDC区别