Skip to content

Commit

Permalink
Included factorial via recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
lnugraha authored May 30, 2024
1 parent d624072 commit d15ef06
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions 2024_05_31_DataStructures/factorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def factorial_iteration(n):

return result

def factorial_recursion(n):
# TODO: Can you add input checkers here?
# TODO: Can you add a simple unit test here
if (n==0 or n==1):
return 1

return n * factorial_recursion(n-1)

def factorial_dynamic_programming(n):
if type(n) is str:
raise TypeError("Cannot have string factorial")
Expand Down

0 comments on commit d15ef06

Please sign in to comment.