Last active
May 19, 2024 12:03
-
-
Save mauricioabreu/c8be64fc9ab7c6b3848a5d75c18717eb to your computer and use it in GitHub Desktop.
Sum numbers recursive
This file contains 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 sum_numbers_recursive(numbers): | |
if not numbers: | |
return 0 | |
return numbers.pop() + sum_numbers_recursive(numbers) | |
sum_numbers_recursive([1, 2, 3]) | |
# complexity | |
# time = O(n) | |
# space = O(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment