From ed557367383ab0df57e47074fcd751bcaba2308d Mon Sep 17 00:00:00 2001 From: reoaah Date: Thu, 20 May 2021 14:37:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A00509.=E6=96=90=E6=B3=A2?= =?UTF-8?q?=E9=82=A3=E5=A5=91=E6=95=B0.md=20Go=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0509.斐波那契数.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 +} +```