码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode-mid-math-172. Factorial Trailing Zeroes-NO-????

时间:2019-06-06 14:05:10      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:大于   div   mamicode   factorial   问题:   int   一个   while   color   

mycode

问题:为甚在小于200的时候,答案ok,大于等于200的时候,就少一个1???

class Solution(object):
    def trailingZeroes(self, n):
        """
        :type n: int
        :rtype: int
        """
        if n<1:
            return 0
        k = 5
        count = 0
        while n // k:
            count += n // k
            k = k*k
        #count_2 = 1 if n%10==0 else 0
        #if n < 200:
        #    return count
        return count 
    #30-》 30 .。25.。。20。。15.。。没有数25中的另外一个5!
    

技术图片

 

参考

class Solution(object):
    def trailingZeroes(self, n):
        """
        :type n: int
        :rtype: int
        """
        return 0 if n == 0 else n / 5 + self.trailingZeroes(n / 5)

 

leetcode-mid-math-172. Factorial Trailing Zeroes-NO-????

标签:大于   div   mamicode   factorial   问题:   int   一个   while   color   

原文地址:https://www.cnblogs.com/rosyYY/p/10984284.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!