Skip to content

Commit

Permalink
Update 0509.斐波那契数.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghongcheng authored Jun 1, 2023
1 parent ed4543b commit 28cf557
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions problems/0509.斐波那契数.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,9 @@ class Solution {
```

### Python
动态规划(版本一)
```python
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:

Expand All @@ -238,7 +229,24 @@ class Solution:
# 返回答案
return dp[n]

# 递归实现
```
动态规划(版本二)
```python
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


```
递归(版本一)
```python

class Solution:
def fib(self, n: int) -> int:
if n < 2:
Expand Down

0 comments on commit 28cf557

Please sign in to comment.