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 ans = 0;
while(n){
ans += n / 5;
n /= 5;
}
return ans;
}
};
计算阶乘尾部零的数量
本文介绍了一种计算给定整数阶乘尾部零数量的方法,通过使用对数运算实现,确保了时间复杂度为对数级。
1215

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



