斐波那契数列:
时间复杂度:
空间复杂度:
class Solution {
public:
int numWays(int n) {
if (0 == n || 1 == n) return 1;
if (2 == n) return 2;
int first = 1, second = 2;
int third;
for (int i = 3; i <=n; ++i) {
third = (first + second) % 1000000007;
first = second;
second = third;
}
return third;
}
};
博客提及力扣地址,重点围绕斐波那契数列,涉及该数列的时间复杂度和空间复杂度相关内容,属于信息技术领域算法相关知识。

被折叠的 条评论
为什么被折叠?



