题目描述:大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项。n<=39
思路:先进行了存储
ac代码:
public class Solution { static int str[]=new int[39]; static { str[0]=1; str[1]=1; for(int i=2;i<39;i++) { str[i]=str[i-1]+str[i-2]; } } public int Fibonacci(int n) { if(n==0) return 0; return str[n-1]; } }