LeetCode solutions

1013. Fibonacci Number

My accepted Python solution to LeetCode problem 1013, Fibonacci Number, running in 13ms.

  • Difficulty: Easy
  • Python
  • Runtime 13ms
  • Memory 12.6MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 13ms, memory 12.6MB, accepted 2025-12-24.

python
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

Source