您的位置:首页 > 大数据 > 人工智能

<LeetCode><Easy> 172 Factorial Trailing Zeroes

2015-10-16 13:09 453 查看
Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

#Python2 44ms

class Solution(object):
def trailingZeroes(self, n):
"""
:type n: int
:rtype: int
"""
counts,delt=0,5
while 1:
increase=n/delt
if not increase:
return counts
counts+=increase
delt*=5


#Python2 递归 64ms

class Solution(object):
def trailingZeroes(self, n):
"""
:type n: int
:rtype: int
"""
getCounts=lambda n,delt=5:getCounts(n,delt*5)+n/delt if delt<=n else 0
return getCounts(n)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode python