Topic description
We all know the Fibonacci sequence, and now you're going to need to enter an integer n, so you output the nth item in the Fibonacci sequence. n<=39 Requirements
Time limit: 1 seconds space limit: 32768K knowledge Point
Fibonacci Series: 1,1,2,3,5,8,13 ....
Observations found: F (1) = 1 F (2) =1 f (3) = f (2) +f (1) = 2 F (4) =f (3) +f (2) ...
F (n) = f (n-1) +f (n-2)
The first item of the series is equal to 1, the second item of the sequence equals 2, and when N>2, the latter is equal to the sum of the first two. Code Implementation
public int Fibonacci (int n) {
if (n==0) {return
0;
}
int[] array = new int[39];
Array[0]=1;
Array[1]=1;
for (int i=2;i<n;i++) {
array[i]=array[i-1]+array[i-2];
System.out.print ("" "+array[i]);
}
return array[n-1];
}
Welcome you to pay attention to my sword refers to the offer blog column, not regularly updated blog content, the wrong place welcome everyone to come forward and learn together.