Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
结尾0只能由因素5、10、15得到,注意就是25,125中5的个数!
class Solution {
public:
int trailingZeroes(int n) {
int ret = 0;
while(n){
ret += n/5;
n /=5;
}
return ret;
}
};