//面试题9:菲波那切数列
//斐波那契函数定义: //F(0)=0,F(1)=1,F(n)=F(n-1)+F(n-2)(n≥2,n∈N*)
package com.hb.jzoffer; //面试题9:菲波那切数列 public class Fibonacci_9 { public long Fibonacci(int n){ int result[] = {0 , 1}; if(n < 2){ return result[n]; } long fibNMinusOne = 1 ; long fibNMinusTwo = 0; long fibN = 0; for(int i = 2 ; i <= n ; i++){ fibN = fibNMinusOne + fibNMinusTwo ; fibNMinusTwo = fibNMinusOne ; fibNMinusOne = fibN; } return fibN; } }