首页 > 代码库 > [leetcode] Factorial Trailing Zeroes

[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

 

[leetcode] Factorial Trailing Zeroes