原标题:LintCode 题目:斐波纳契数列简单
原文来自:CSDN 原文链接:https://blog.csdn.net/qq_42410605/article/details/102903430
描述
Find the Nth number in Fibonacci sequence.
A Fibonacci sequence is defined as follow:
The first ten numbers in Fibonacci sequence is:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34 ...
N <= 20
样例
Example 1:
Input: 1
Output: 0
Explanation:
return the first number in Fibonacci sequence .
Example 2:
Input: 2
Output: 1
Explanation:
return the second number in Fibonacci sequence .
(1)通过率:100%(使用递归)
在程序中添加方法:
static int lcc(int x){
if(x==1)
return 0;
else if(x==2)
return 1;
else
return lcc(x-1)+lcc(x-2);
}
在代码段中添加:
return lcc(n);
即可:
免责声明:本文来自互联网新闻客户端自媒体,不代表本网的观点和立场。
合作及投稿邮箱:E-mail:editor@tusaishared.com