判断n的阶乘里有多少个0:
class Solution {
public:
int trailingZeroes(int n)
{
int ans=0;
while(n)
{
n /= 5;
ans += n;
}
return ans;
}
};
本文介绍了一种高效计算任意正整数n的阶乘结果中尾部0的数量的方法。通过一个简单的C++代码实现,该算法能快速找出阶乘结果中连续0的数量。
判断n的阶乘里有多少个0:
class Solution {
public:
int trailingZeroes(int n)
{
int ans=0;
while(n)
{
n /= 5;
ans += n;
}
return ans;
}
};

被折叠的 条评论
为什么被折叠?
