难易程度 简单
题目描述:
Find the Nth number in Fibonacci sequence.(译:如题)
A Fibonacci sequence is defined as follow:
斐波那契数列的定义如下:
The first two numbers are 0 and 1.
数列的前两个数从0,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 ...
Notice
The Nth fibonacci number won't exceed the max value of signed 32-bitinteger in the test cases.
测试用例中第N个斐波那契数列的值不会超过int的最大值(翻译可能不太准确哈...英语不好(⊙﹏⊙))
思路:
这道题非常耿直,比起青蛙跳阶梯,铺方砖等需要思考之后才能总结出可以使用斐波那契数列来结的算法,实在是面试中考算法的良心题目了。直接简明扼要的指出了是斐波那契数列,计算斐波那契数列常用的算法有两种:
递归