版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jsszwc/article/details/88074755
题目:
https://leetcode-cn.com/problems/factorial-trailing-zeroes/
题意:
给定一个整数 n,返回 n! 结果尾数中零的数量。
思路:
只有数字 才能使积的末尾有零, 类似数据均可以抽离出 ,所以只需求 中,可以抽离出多少对 即可,又因为肯定 的数量少,所以求 中因子 的个数
代码:
class Solution {
public:
int trailingZeroes(int n) {
int ans = 0;
while(n) {
n /= 5;
ans += n;
}
return ans;
}
};