Skip to content

Instantly share code, notes, and snippets.

@mauricioabreu
Last active May 19, 2024 12:03
Show Gist options
  • Save mauricioabreu/c8be64fc9ab7c6b3848a5d75c18717eb to your computer and use it in GitHub Desktop.
Save mauricioabreu/c8be64fc9ab7c6b3848a5d75c18717eb to your computer and use it in GitHub Desktop.
Sum numbers recursive
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