Factorial Trailing Zeroes——Math

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

class Solution(object):
    def trailingZeroes(self, n):
        """
        :type n: int
        :rtype: int
        """
        result = 0
        t = 5
        while t <= n:
        	result += n/t
        	t *= 5
        return result

 

猜你喜欢

转载自qu66q.iteye.com/blog/2318069
今日推荐