-
Notifications
You must be signed in to change notification settings - Fork 623
Expand file tree
/
Copy pathCount Zeros.py
More file actions
42 lines (34 loc) · 815 Bytes
/
Count Zeros.py
File metadata and controls
42 lines (34 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
-------------------------------------- Count Zeros -------------------------------------------
Given an integer N, count and return the number of zeros that are present in the given integer using recursion.
#### Input Format :
Integer N
#### Output Format :
Number of zeros in N
#### Constraints :
0 <= N <= 10^9
#### Sample Input 1 :
10204
#### Sample Output 1 :
2
#### Sample Input 2 :
708000
#### Sample Output 2 :
4
"""
def countZeros(n):
if n<0:
n *= -1 # Make n positive
if n<10:
if n == 0:
return 1
return 0
smallAns = countZeros(n // 10)
if n%10==0:
smallAns += 1
return smallAns
# Main
from sys import setrecursionlimit
setrecursionlimit(11000)
n=int(input())
print(countZeros(n))