问题描述
解决方案
我的解决方法
class Solution {
public:
int climbStairs(int n) {
int a=1,b=1;
for(int i=1;i<n;++i)
{
b+=a;
a=b-a;
}
return b;
}
};
网上的解决方法
class Solution {
public:
int climbStairs(int n) {
return (pow((1.0+sqrt(5.0))/2.0,n+1)-pow((1.0-sqrt(5.0))/2.0,n+1))/sqrt(5.0);
}
};