Write an algorithm which computes the number of trailing zeros in n factorial.
Example
11! = 39916800, so the out should be 2
Challenge
O(log N) time
public class Solution {
public int trailingZeroes(int n) {
if (n < 0) {
return -1;
}
int count = 0;
for (; n > 0; n /= 5) {
count += (n / 5);//第二次计算时就代表除以25...
}
return count;
}
}