diff --git a/problems/0509.斐波那契数.md b/problems/0509.斐波那契数.md index 112c96f9..5afcd6b8 100644 --- a/problems/0509.斐波那契数.md +++ b/problems/0509.斐波那契数.md @@ -207,6 +207,19 @@ class Solution: ``` Go: +```Go +func fib(n int) int { + if n < 2 { + return n + } + a, b, c := 0, 1, 0 + for i := 1; i < n; i++ { + c = a + b + a, b = b, c + } + return c +} +```