题目要求

The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,

  F(0) = 0,   F(1) = 1​

  F(N) = F(N - 1) + F(N - 2), for N > 1.​

Given N, calculate F(N).

题目分析及思路

题目给出斐波那契数列,要求返回第n个数字。可使用列表存放数列。

python代码​

class Solution:

def fib(self, N):

"""

:type N: int

:rtype: int

"""

res = [0,1]

for i in range(2,N+1):

res.append(res[i-1]+res[i-2])

return res[N]

LeetCode 509 Fibonacci Number 解题报告的更多相关文章

  1. 【LeetCode】509. Fibonacci Number 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetc ...

  2. 【LeetCode】Largest Number 解题报告

    [LeetCode]Largest Number 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/largest-number/# ...

  3. LeetCode 136 Single Number 解题报告

    题目要求 Given a non-empty array of integers, every element appears twice except for one. Find that sing ...

  4. Leetcode 509. Fibonacci Number

    class Solution(object): def fib(self, N): """ :type N: int :rtype: int ""&q ...

  5. 【LeetCode】873. Length of Longest Fibonacci Subsequence 解题报告(Python)

    [LeetCode]873. Length of Longest Fibonacci Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: ...

  6. 【LeetCode】306. Additive Number 解题报告(Python)

    [LeetCode]306. Additive Number 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...

  7. 【LEETCODE】44、509. Fibonacci Number

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  8. 【leetcode】509. Fibonacci Number

    problem 509. Fibonacci Number solution1: 递归调用 class Solution { public: int fib(int N) { ) return N; ...

  9. LeetCode 1 Two Sum 解题报告

    LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...

随机推荐

  1. 【iCore4 双核心板_ARM】例程十二:通用定时器实验——定时点亮LED

    实验原理: 通过STM32的三个GPIO口来驱动LED灯的三个通道,设定GPIO为推挽输出模式,采 用灌电流的方式与LED连接,输出高电平LED灭,输出低电平LED亮,通过通用定时器TIM3 实现50 ...

  2. cvCreateImage

    CvCreateImage函数说明 cvCreateImage是openCV中的一个函数.OpenCV是Intel公司支持的开源计算机视觉库.   cvCreateImage:   创建头并分配数据 ...

  3. Java知多少(89)列表和组合框

    有两种类型的菜单:下拉式菜单和弹出式菜单.本章只讨论下拉式菜单编程方法.菜单与JComboBox和JCheckBox不同,它们在界面中是一直可见的.菜单与JComboBox的相同之处是每次只可选择一个 ...

  4. Qt读写ini文件

    一 背景 1 ini文件介绍 .ini 文件是Initialization File的缩写,即初始化文件. 除了windows现在很多其他操作系统下面的应用软件也有.ini文件,用来配置应用软件以实现 ...

  5. 实验室ubuntu连ipv6

    1.买个极路由 2.无线中继连tsinghua-5G 3.安装ipv6插件 4.联网或者科协vpn 5.下载bt客户端:sudo apt-get install qbittorrent   (或者su ...

  6. 【转载】VC维,结构风险最小化

    以下文章转载自http://blog.sina.com.cn/s/blog_7103b28a0102w9tr.html 如有侵权,请留言,立即删除. 1 VC维的描述和理解 给定一个集合S={x1,x ...

  7. python初级 2 字符串格式化

    一.回顾 上次我们讲解的数据类型,有int,float,str,bool,NoneType五种 前两种和后两种都比较简单,str较为复杂 二.字符串格式化的使用场景: 有一种字符串, xxx 的内容都 ...

  8. [Hinton] Neural Networks for Machine Learning - Bayesian

    Link: Neural Networks for Machine Learning - 多伦多大学 Link: Hinton的CSC321课程笔记 Lecture 09 Lecture 10 提高泛 ...

  9. OpenGL——二次曲面函数(球面-圆锥面-圆柱面)

    代码: #include<iostream> #include <math.h> #include<Windows.h> #include <GL/glut. ...

  10. linux 下修改键盘映射

    参考文档 原因: 输入 键盘原本的 “\ |”,结果映射到 "< >",而 < 与 > 对应的键名分别是 less 与 greater 查看键名: xev ...