标签:
本题有一个简单的递推式:
注意点:
class Solution {
public:
int climbStairs(int n) {
if (n < 0)
return 0;
if (n <= 2)
return n;
int a1 = 1, a2 = 2;
int res = 0;
for (size_t i = 3; i <= n; i++)
{
res = a1 + a2;
a1 = a2;
a2 = res;
}
return res;
}
};
标签:
原文地址:http://www.cnblogs.com/flyjameschen/p/4322779.html