class Solution:
"""
@param: n: An integer
@return: An integer, denote the number of trailing zeros in n!
"""
def trailingZeros(self, n):
# write your code here, try to do it without arithmetic operators.
res = 0
tp = 5
while n/tp>=1:
res = res + int(n/tp)
tp = tp * 5
return resPython, LintCode, 2. 尾部的零
最新推荐文章于 2022-05-07 08:58:12 发布
本文介绍了一种高效计算任意正整数n的阶乘(n!)末尾零的数量的方法。通过迭代地除以5的幂次来累加结果,避免了直接计算阶乘所带来的巨大数值运算开销。
3859

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



