mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
添加0509.斐波那契数.md Go版本
This commit is contained in:
@ -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
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user