Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 464 Bytes

509.md

File metadata and controls

33 lines (24 loc) · 464 Bytes

509 Fibonacci Number

Description

link


Solution

  • See Code

Code

class Solution:
    def fib(self, N: int) -> int:
        if N == 0:
            return 0
        if N == 1:
            return 1
        x_0 = 0
        x_1 = 1
        for i in range(2, N + 1):
            x_2 = x_0 + x_1
            x_0 = x_1
            x_1 = x_2
        return x_2