数学题emmm 😅
java:
class Solution {
public int trailingZeroes(int n) {
int count = 0;
while(n > 0){
count += n / 5;
n /= 5;
}
return count;
}
}
python3:
class Solution:
def trailingZeroes(self, n: int) -> int:
ans = 0
while n > 0:
ans += n // 5
n //= 5
return ans
本文提供了一种高效计算任意正整数阶乘后尾随0的数量的方法。使用Java和Python实现,通过不断除以5的倍数来统计在阶乘过程中能贡献0的因子对的数量。
793

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



