<LeetCode><Easy> 172 Factorial Trailing Zeroes

来源:互联网 发布:百度自动推送代码js 编辑:程序博客网 时间:2024/06/05 18:38

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)


0 0
原创粉丝点击