剑指offer 7 斐波那契数列

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

public class Solution {
    public int Fibonacci(int n) {
        return func(n);
    }
    public int func(int n){
        if(n == 0 || n == 1)
            return n;
        return func(n-1)+func(n-2);
    }
}

猜你喜欢

转载自blog.csdn.net/u011144603/article/details/89061009