【leetcode】Factorial Trailing Zeroes(easy)

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

Note: Your solution should be in logarithmic time complexity.

 

思路:编程之美里有,就是找因子5的个数。

int trailingZeroes(int n) {

        int ans = 0;

        while(n > 0)

        {

            ans += n / 5;

            n /= 5;

        }

        return ans;

    }

 

你可能感兴趣的:(LeetCode)