-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfib.py
More file actions
24 lines (20 loc) · 496 Bytes
/
Copy pathfib.py
File metadata and controls
24 lines (20 loc) · 496 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# coding=utf-8
"""
@project : algorithmPython
@ide : PyCharm
@file : fib
@author : illusion
@desc : 509. 斐波那契数 https://leetcode-cn.com/problems/fibonacci-number/
@create : 2021/8/20 1:16 下午:20
"""
class Solution:
def fib(self, n: int) -> int:
if n == 0:
return 0
dp1 = 0
dp2 = 1
for i in range(2, n + 1):
dp1, dp2 = dp2, dp1 + dp2
return dp2
if __name__ == '__main__':
print(Solution().fib(4))