LeetCode. 阶乘后的零

题目要求:

给定一个整数 n,返回 n! 结果尾数中零的数量。

示例:

输入: 3
输出: 0
解释: 3! = 6, 尾数中没有零。

解法:

class Solution {
public:
    int trailingZeroes(int n) {
        int result = 0;
        while(n) {
            n /= 5;
            result += n;
        }
        return result;
    }
};
posted @ 2019-10-18 01:15  Howardwang  阅读(111)  评论(0编辑  收藏  举报