Created
April 28, 2026 14:37
-
-
Save haydenk/c29518aa2215fd059363229505f5db47 to your computer and use it in GitHub Desktop.
[Python] Recursive Fibonacci with type hints; handles negative inputs by taking the absolute value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fibonacci(n: int) -> int: | |
| abs_n: int = abs(n) | |
| if abs_n < 2: | |
| return 0 | |
| if abs_n < 3: | |
| return 1 | |
| return fibonacci(abs_n - 1) + fibonacci(abs_n - 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment