首页 > 代码库 > 爬楼梯

爬楼梯

class Solution {
public:
/**
* @param n: An integer
* @return: An integer
*/
int climbStairs(int n) {


if(n <= 1)
return 1;
if(n ==2)
return 2;

int result;
int a = 1;
int b = 2;

for(int i = 3;i<=n;i++){
result = a + b;
a = b;
b = result;
}
return result;

}
};

爬楼梯