Trailing Zeros 算法
Write an algorithm which computes the number of trailing zeros in n factorial.
public class Solution {
/*
* @param n: An integer
* @return: An integer, denote the number of trailing zeros in n!
*/
public long trailingZeros(long n) {
// write your code here, try to do it without arithmetic operators.
// long result = trailingZeros(n-1)*n ;
long i = 0 ;
while(n != 0){
i += n/5 ;
n /= 5 ;
}
return i ;
}
}