172. factorial trailing zeroes

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public:
int (int n) {
int res = 0;
while (n) {
res += n / 5;
n /= 5;
}
return res;
}
};