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.
Subscribe to see which companies asked this question
思路:就是看有几个5的因子。 也是写了很多遍,逐渐填补上的漏洞。深深觉得自己bug free的能力欠缺的不是一星半点呢。
public class Solution {
public int trailingZeroes(int n) {
int m = n;
int k = 0;
int res = 0;
while(m/5 > 0){
k++;
m = m/5;
}
for(int i = 1; i <= k; i++){
res += n/(Math.pow(5,i));
}
return res;
}
}
转载请注明原文地址: https://ju.6miu.com/read-1300039.html