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.
Have you met this question in a real interview?
思路 : cc150 上的原题, 查 5 的个数 + 25 的个数 + 125 的个数
leetcode 用乘积会超时, 于是改成往下除。
public class Solution {
public int trailingZeroes(int n) {
if(n < 5)
return 0;
int ret = 0;
while(n > 0){
ret += n/5;
n /= 5;
}
return ret;
}
}