1013. Fibonacci Number
My accepted Python solution to LeetCode problem 1013, Fibonacci Number, running in 13ms.
- Difficulty: Easy
- Python
- Runtime 13ms
- Memory 12.6MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 13ms, memory 12.6MB, accepted 2025-12-24.
class Solution(object):
def fib(self, n):
if n <= 1:
return n
a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b
return b