Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
就是返回 n! 这个数里“零的个数”
public class Solution {
public int trailingZeroes(int n) {
int result = 0;
if (n < 0) {
return -1;
} else if (n < 5) {
return 0;
} else {
while (n != 0) {
n = n/5;
result += n;
}
}
return result;
}
}
本文介绍了一种算法,用于计算给定整数n的阶乘中尾部零的数量,利用对数时间复杂度实现。
7661

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



