Title Description
We all know that Fibonacci number, and now asked to enter an integer n, you output the n-th Fibonacci number Fibonacci sequence of item (from 0, the first 0 is 0)
Dynamic Programming
Item i = i-1 th item of the i-2 + items
public int Fibonacci(int n) {
if(n<=1) return n;
int m1=0;
int m2=1;
int sum=0;
for(int i=2;i<=n;i++){
sum=m1+m2;
m1=m2;
m2=sum;
}
return sum;
}