【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;
    }

 

posted @ 2015-04-17 14:21  匡子语  阅读(124)  评论(0编辑  收藏  举报