Skip to content

Commit 64841b1

Browse files
committed
509
1 parent b57fa56 commit 64841b1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Math/509.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## 509 Fibonacci Number
2+
3+
#### Description
4+
5+
[link](https://leetcode.com/problems/fibonacci-number/)
6+
7+
---
8+
9+
#### Solution
10+
11+
- See Code
12+
13+
---
14+
15+
#### Code
16+
17+
<!-- O(n) -->
18+
19+
```python
20+
class Solution:
21+
def fib(self, N: int) -> int:
22+
if N == 0:
23+
return 0
24+
if N == 1:
25+
return 1
26+
x_0 = 0
27+
x_1 = 1
28+
for i in range(2, N + 1):
29+
x_2 = x_0 + x_1
30+
x_0 = x_1
31+
x_1 = x_2
32+
return x_2
33+
```

0 commit comments

Comments
 (0)