剑指Offer 斐波那契数列

时间限制:1秒 空间限制:32768K 热度指数:332130

 算法知识视频讲解

题目描述

大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项。

n<=39

给出代码:

class Solution {
public:
    int Fibonacci(int n) {

    }
};

  

水题

AC代码:

class Solution {
public:
    int Fibonacci(int n) {
    int a[50];
    a[0] = 0;
    a[1] = 1;
    for(int i = 2; i <= 40; i++) {
        a[i] = a[i-1] + a[i-2];
    }
        return a[n];
    }
};

  

posted @ 2018-07-03 14:41  Hyouka  阅读(130)  评论(0编辑  收藏  举报