[leedcode 172] Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

public class Solution {
    public int trailingZeroes(int n) {
        //求几个0主要考虑的是5的个数
        if(n==0) return 0;
        int res=0;
        while(n>0){
            res+=n/5;
            n=n/5;
        }
        return res;
    }
}
原文地址:https://www.cnblogs.com/qiaomu/p/4696336.html