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

 

你可能感兴趣的:(Leecode,Python)