Total Accepted: 58597
Total Submissions: 178269
Difficulty: Easy
Have you met this question in a real interview?
Yes
No
Discuss Notes
class Solution {
public:
int trailingZeroes(int n) {
int ans=0;
while(n)
{
ans+=n/5;
n/=5;
}
return ans;
}
};
本文介绍了一种高效算法,用于计算给定整数n的阶乘中末尾0的数量。该算法通过不断除以5并累加商值来得出结果,确保了时间复杂度为对数级别。
729

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



