Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
主要是思考清楚计算过程:
将一个数进行因式分解,含有几个5就可以得出几个0(与偶数相乘)。
代码很简单。
public class Solution { public int trailingZeroes(int n) { int result = 0; long num = 5; long div = (long) n; while (div / num != 0){ result += div / num; num *= 5; } return result; } }