您的位置:首页 > 编程语言 > Python开发

python - LintCode 2. 尾部的零

2018-03-30 10:38 459 查看

2. 尾部的零 

设计一个算法,计算出n阶乘中尾部零的个数样例11! = 39916800,因此应该返回 2挑战 O(logN)的时间复杂度解决思路:
n!尾部出现0必定满足其有因子为5或者5^m(m>1,且为整数)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 operator
result = 0
temp = n // 5
while temp != 0 :
result += temp
temp //= 5
return result
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  lintcode python