Add product of numbers using recursion

pull/803/head
WORLDSAVER 2022-08-16 07:58:48 +05:30
parent 7626447a82
commit 24ad6d3eed
1 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,15 @@
#PRODUCT OF NUMBERS
def productNum(N):
if N//10==0:
return N
else:
return N%10 * productNum(N//10)
# TIME COMPLEXITY - O(M) where M is length of digits of number N.
# SPACE COMPLECITY - O(M) where M is length of digits of number N.
# EXAMPLES
# print(productNum(123)) -> 6
# print(productNum(222)) -> 8