剑指offer(斐波那契数列)
- 避免递归造成的调用栈消耗
1
2
3
4
5
6
7
8
9
10
11public class Solution {
public int Fibonacci(int n) {
int a = 0;
int b = 1;
while(n-->0){
b = a + b;
a = b - a;
}
return a;
}
} - 复杂度
时间复杂度:O(n)O(n)
空间复杂度:O(1)O(1)
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 右郁石!
评论


