Skip to content

Commit fefe215

Browse files
author
applewjg
committed
add recursion solution
Change-Id: I4c99fbc284777b3be13eeee16feecc39dd5f6aa8
1 parent a0d592a commit fefe215

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

FactorialTrailingZeroes.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
Solution: ...
1313
*/
1414
public class Solution {
15-
public int trailingZeroes(int n) {
15+
public int trailingZeroes_1(int n) {
1616
int res = 0;
1717
while (n != 0) {
1818
res += n / 5;
1919
n = n / 5;
2020
}
2121
return res;
2222
}
23+
public int trailingZeroes_2(int n) {
24+
if (n == 0) return 0;
25+
return n / 5 + trailingZeroes_2(n / 5);
26+
}
2327
}

0 commit comments

Comments
 (0)