Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

函数一章中答案 A10 关于斐波那契函数的问题 #15

Closed
onion7878 opened this issue Nov 19, 2014 · 0 comments
Closed

函数一章中答案 A10 关于斐波那契函数的问题 #15

onion7878 opened this issue Nov 19, 2014 · 0 comments
Assignees

Comments

@onion7878
Copy link
Contributor

func fibonacci(value int) []int {
    x := make([]int, value)
    x[0], x[1] = 1, 1
    for n := 2; n < value; n++ {
        x[n] = x[n-1] + x[n-2]
    }
    return x
}

原函数在参数为1时会报错

func fibonacci(n int) []int {
    arr := make([]int, n)
    a, b := 0, 1
    for i := 0; i < n; i++ {
        a, b = b, a+b
        arr[i] = a
    }
    return arr
}

参考了:fib.go

@mikespook mikespook self-assigned this Nov 20, 2014
mikespook added a commit that referenced this issue Nov 20, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants