乐趣区

关于go:Leetcode专题数组剑指offer10I斐波那契数列

leetcode 链接:
https://leetcode.cn/problems/fei-bo-na-qi-shu-lie-lcof/soluti…
解题思路:
递归

func fib(n int) int {
    if n == 0 || n == 1 {return n}
    a,b := 0, 1
    for i := 2; i <= n; i++ {a, b = b, (a+b) % 1000000007
    }
    return b
}
退出移动版