斐波那契

你們都知道斐波那契數列,如今要求輸入一個整數n,請你輸出斐波那契數列的第n項。
 
 
public class Solution {
     public int Fibonacci( int n) {
         int target= 0 ;
         if (n== 0 )
             return 0 ;
         if (n== 1 )
             return 1 ;
         int one= 0 ;
         int two= 1 ;
         for ( int i= 2 ;i<=n;i++){
             target=one+two;
             one=two;
             two=target;
         }
         return target;
 
     }
}
相關文章
相關標籤/搜索