Last active
November 22, 2020 23:41
-
-
Save ZhouYang1993/edabfa57de69ba6ca8ce1bb2a9edb2a9 to your computer and use it in GitHub Desktop.
medium 1
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 factorial(n): | |
if n == 1: | |
return 1 | |
return factorial(n - 1) * n | |
print(factorial(4)) | |
def tailRecursionFactorial(n, acc): | |
if n == 1: | |
return acc | |
return tailRecursionFactorial(n - 1, acc * n) | |
print(tailRecursionFactorial(4,1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment