牛客网 | 斐波那契数列

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

public class Solution {
    public int Fibonacci(int n) {
		
        if(n<=1) return n;
        int a = 0;
        int b = 1;
        int c = 0;
        
        while(--n>0)
        {
            c = a+b;
            a = b;
            b = c;
        }
        return c;
    }
}


你可能感兴趣的:(java)