标签:int += bubuko 爬楼梯 info span size for 思路
思路:为了爬到n层楼梯,有两个选择,在n-1阶前进1步 or 在 n-1阶前进2步,即f(n) = f(n-1) + f(n-2)
class Solution {
public:
int climbStairs(int n) {
int prev = 0;
int cur = 1;
for(int i=1; i<=n; i++)
{
int tmp = cur;
cur += prev;
prev = tmp;
}
return cur;
}
};
标签:int += bubuko 爬楼梯 info span size for 思路
原文地址:https://www.cnblogs.com/573177885qq/p/10245485.html