纯粹个人记录 题目出处
递归
public static int Fibonacci(int n ){
switch (n){
case 0: return 0;
case 1: return 1;
case 2: return 1;
}
return Fibonacci(n-1)+Fibonacci(n-2);
}
动态规划
public static int Fibonacci(int n ){
int f =0,g=1;
while(n-->0){
g += f;
f=g-f;
}
return f;
//return Fibonacci(n-1)+Fibonacci(n-2);
}