[leetcode] Factorial Trailing Zeroes

Factorial Trailing Zeroes

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

Note: Your solution should be in logarithmic time complexity.

思路:

不会做。先百度阶乘最后有几个零,知道了方法剩下的就很简单了。

很佩服他们,可以想出这个方法

题解:

class Solution {
public:
    int trailingZeroes(int n) {
        int res = 0;
        while(n) {
            n /= 5;
            res += n; 
        }
        return res;
    }
};
View Code
原文地址:https://www.cnblogs.com/jiasaidongqi/p/4226406.html