n!就是1*2*3*4*.......*n,没出现一个5,0就增加一个,比如,103!=1*2*3*4*5*6*7*........*10*.........*103,所所以至少出现5,10,15,20.。。。。100,除以5又得,1,2,3,4,5,。。。。20这又是四个,依次往下,即可
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
public class Solution {
public int trailingZeroes(int n) {
int result = 0;
if(n <= 4){
return 0;
}
while(n/5 != 0){
n/=5;
result += n;
}
return result;
}
}