Java 斐波那契数列简便解法:
##代码
int Fibonacci(int n) {
if (n == 0 || n == 1) return n;
int a = 0, b = 1, c;
for (int i = 2; i <= n; ++i) {
c = a + b;
a = b;
b = c;
}
return c;
}`
时间复杂度 :o(n);
空间复杂度:o(1);
Java 斐波那契数列简便解法:
##代码
int Fibonacci(int n) {
if (n == 0 || n == 1) return n;
int a = 0, b = 1, c;
for (int i = 2; i <= n; ++i) {
c = a + b;
a = b;
b = c;
}
return c;
}`
时间复杂度 :o(n);
空间复杂度:o(1);