Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
思路:有多少个0就是有多少个5. 零的产生就是5和2或者4的乘积,15—》 15*12/14 10*12/14 5*2/4 -》3个。 25拆成5*5所以会多一个。
public class Solution { public int trailingZeroes(int n) { if(n<=0)return 0; int res=0; while(n>0){ res+=n/5; n/=5; } return res; } }