题解 | #斐波那契数列#
斐波那契数列
https://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3
public int Fibonacci(int n) {
int fn1 = 1;
int fn2 = 1;
if(n <= 0){
return 0;
}
for(int i = 3;i < n && n > 2;i+=2){
fn1 += fn2;
fn2 += fn1;
}
return fn2;
}
}
int fn1 = 1;
int fn2 = 1;
if(n <= 0){
return 0;
}
for(int i = 3;i < n && n > 2;i+=2){
fn1 += fn2;
fn2 += fn1;
}
return fn2;
}
}