标签:color solution off 输出 alt span pen pre 输入
【题目描述】
大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)。
n<=39
时间限制:1秒 空间限制:32768K
【AC 代码】
斐波那契数列的标准公式为:F(1)=1,F(2)=1, F(n)=F(n-1)+F(n-2)(n>=3,n∈N*)
注意题目要求斐波那契数列从0开始,且第0项为0。
1 public class Solution { 2 public int Fibonacci(int n) { 3 if (n == 0 || n == 1) return n; 4 return Fibonacci(n-1) + Fibonacci(n-2); 5 } 6 }
标签:color solution off 输出 alt span pen pre 输入
原文地址:https://www.cnblogs.com/moongazer/p/11569666.html