简单
001.尾部的零(Trailing Zeros)
描述:
设计一个算法,计算出n阶乘中尾部零的个数(Write an algorithm which computes the number of trailing zeros in n factorial.)
样例 11! = 39916800,因此应该返回 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 /= 5;
}
return sum;
}
}