172. Factorial Trailing Zeroes
172. Factorial Trailing Zeroes
数阶乘结果的末尾0个数 根据奇偶性可知 2 的个数一定多于 5 的个数,因此 0 的个数取决于 5 的个数,递归数比为5,起始为 5 的等比数列的 5 的个数,递归求解即可
int trailingZeroes(int n) {
if (n == 0) return 0;
return n/5 + trailingZeroes(n/5);
}#递归 #math