Write an algorithm which computes the number of trailing zeros in n factorial.
11! = 39916800, so the out should be 2
class Solution {
/*
* param n: As desciption
* return: An integer, denote the number of trailing zeros in n!
*/
public long trailingZeros(long n) {
// write your code here
long sum = 0; //防止溢出
while(n!=0){
sum += n/5;
n = n/5;
}
return sum;
}
};