斐波那契数列
大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项.
public class Fibonacci { public static int[] record = null; public int Fibonaci(int n){ if(n<=1){ return n; } if(null == record){ record = new int[n+1]; } if(0!=record[n-2] && 0!=record[n-1]){ record[n] = record[n-2] + record[n-1]; } else { return Fibonaci(n-2) + Fibonaci(n-1); } return Fibonaci(n); } }