剑指offer
斐波那契数列
相似的企业真题
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 64M,其他语言128M
热度指数:980040
本题知识点:
数组
算法知识视频讲解
校招时部分企业笔试将禁止编程题跳出页面,为提前适应,练习时请使用在线自测,而非本地IDE。
题目描述
大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0,第1项是1)。
示例1
输入
复制
4
4
返回值
复制
3
3
上一题
下一题
登录
/
注册
我的提交
编辑器加载中...
public class Solution { public int Fibonacci(int n) { } }
class Solution { public: int Fibonacci(int n) { } };
# -*- coding:utf-8 -*- class Solution: def Fibonacci(self, n): # write code here
class Solution { public int Fibonacci(int n) { // write code here } }
function Fibonacci(n) { // write code here } module.exports = { Fibonacci : Fibonacci };
function Fibonacci(n) { // write code here }
# -*- coding:utf-8 -*- class Solution: def Fibonacci(self, n): # write code here
package main /** * * @param n int整型 * @return int整型 */ func Fibonacci( n int ) int { // write code here }
/** * * @param n int整型 * @return int整型 */ int Fibonacci(int n ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param n int整型 # @return int整型 # class Solution def Fibonacci(n) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 * @return int整型 */ def Fibonacci(n: Int): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 * @return int整型 */ fun Fibonacci(n: Int): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 * @return int整型 */ public int Fibonacci (int n) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 * @return int整型 */ export function Fibonacci(n: number): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 * @return int整型 */ func Fibonacci ( _ n: Int) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 * @return int整型 */ pub fn Fibonacci(&self, n: i32) -> i32 { // write code here } }
4
3