斐波那契数列(水题)

题目描述

大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)。

n<=39

public class Solution {
    public int Fibonacci(int n) {
    int f3=0;
    int f1=1;
    int f2=1;
    if(n==0) return 0;
    if(n==1||n==2) return 1;    
    for(int i=3;i<=n;i++){
    f3=f1+f2;
    f1=f2;
    f2=f3;    
    }
    return f3;    
    }
}
不一样的烟火
原文地址:https://www.cnblogs.com/cstdio1/p/11232908.html