添加 0509.斐波那契数 Python3版本

This commit is contained in:
pppig
2021-05-17 22:29:29 +08:00
committed by GitHub
parent c4bfb1f34f
commit 2f2e349247

View File

@ -187,7 +187,24 @@ class Solution {
```
Python
```python3
class Solution:
def fib(self, n: int) -> int:
if n < 2:
return n
a, b, c = 0, 1, 0
for i in range(1, n):
c = a + b
a, b = b, c
return c
# 递归实现
class Solution:
def fib(self, n: int) -> int:
if n < 2:
return n
return self.fib(n - 1) + self.fib(n - 2)
```
Go