爬楼梯

class Solution {
public:
/**
* @param n: An integer
* @return: An integer
*/
int climbStairs(int n) {
// write your code here
int a = 1, b = 1, k = 0;
if(n == 1 || n ==0){
return 1;
}
while(--n > 0){
k = a+b;
b = a;
a = k ;
}
return k;
}
};

posted on 2017-03-08 18:02  暴走的跳跳糖  阅读(90)  评论(0编辑  收藏  举报

导航