资源经验分享LintCode 题目:斐波纳契数列简单

LintCode 题目:斐波纳契数列简单

2019-11-06 | |  121 |   0

原标题:LintCode 题目:斐波纳契数列简单

原文来自:CSDN      原文链接:https://blog.csdn.net/qq_42410605/article/details/102903430


URL:https://www.lintcode.com/problem/fibonacci-easy/description

描述

Find the Nth number in Fibonacci sequence.

A Fibonacci sequence is defined as follow:

  • The first two numbers are 0 and 1.

  • The i th number is the sum of i-1 th number and i-2 th number.

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);

即可:
1.png

 

相似题型:LintCode 题目:斐波纳契数列

 

 

免责声明:本文来自互联网新闻客户端自媒体,不代表本网的观点和立场。

合作及投稿邮箱:E-mail:editor@tusaishared.com

上一篇:目标检测之数据集增强(旋转)

下一篇:C++数据结构二叉树统计总结点个数,叶子结点个数,单分支结点个数,双分支结点个数。(markdown)

用户评价
全部评价

热门资源

  • TensorFlow从1到2...

    原文第四篇中,我们介绍了官方的入门案例MNIST,功...

  • TensorFlow从1到2...

    “回归”这个词,既是Regression算法的名称,也代表...

  • 盲源分离算法学习笔记

    麦克风阵列算法有两大类,一类是波束形成算法,另...

  • TensorFlow从1到2...

    前面所展示的一些示例已经很让人兴奋。但从总体看...

  • python竟能绘制出...

    听说python语言在编程界排名又升了,其热度堪比此...