leetcode--斐波那契数列

输入一个整数n,请你输出斐波那契数列的第n项

 

# -*- coding:utf-8 -*-


def fibonacci_num(n):
    if n == 0 or n == 1:
        return 1

    s, t1, t2 = 0, 1, 1
    t = 2
    while t <= n:
        s = t1+t2

        t1 = t2
        t2 = t
        t += 1

    return s

print('result:', fibonacci_num(5))

 

posted @ 2021-09-27 09:26  techPark  阅读(23)  评论(0)    收藏  举报