diff --git a/Recursion 1/CountZero.java b/Recursion 1/CountZero.java index 55a35d4..da906a1 100644 --- a/Recursion 1/CountZero.java +++ b/Recursion 1/CountZero.java @@ -3,14 +3,21 @@ public class solution { public static int countZerosRec(int input){ // Write your code here - if(input == 0) - return 0; - if(input % 10 == 0){ - return countZerosRec(input / 10) + 1; - } - else{ - return countZerosRec(input / 10); - } + if(input/10 == 0) { + + if(input == 0) { + return 1; + } + return 0; + } + + + + int smallAns = countZerosRec(input/10); + if(input % 10 == 0) { + return smallAns + 1; + } + return smallAns; } public static void main(String[] args) {