zoukankan      html  css  js  c++  java
  • 1807. 斐波纳契数列简单

    1807. 斐波纳契数列简单

    中文English

    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 ...

    样例

    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 .
    
    

    注意事项

    N <= 20

    输入测试数据 (每行一个参数)如何理解测试数据?
    class Solution:
        """
        @param n: an integer
        @return: an ineger f(n)
        """
        '''
        大致思路:
        1.前两个是固定的[0,1],后面的就根据前面的两个相加,到指定长度返回。
        '''
        def fibonacci(self,n):
            dic=[0,1]
            for i in range(n-2):
                dic.append(dic[-1]+dic[-2])
            return dic[n-1]
  • 相关阅读:
    route命令
    自动删除n天前日志
    ss命令
    rcp命令
    crontab,at命令,常见问题
    locate,nl命令
    kill,killall,top,free,vmstat,iostat,watch命令
    [转载]memcached stats 命令
    Swift学习笔记
    C++移位运算符
  • 原文地址:https://www.cnblogs.com/yunxintryyoubest/p/12817412.html
Copyright © 2011-2022 走看看