Skip to content
LC-0172 Medium LeetCode

172. Factorial Trailing Zeroes

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 45% Topics: Math
View full problem on LeetCode

Reading material

Reference solution (spoiler · python)
# Time:  O(logn) = O(1)
# Space: O(1)

class Solution(object):
    # @return an integer
    def trailingZeroes(self, n):
        result = 0
        while n > 0:
            result += n / 5
            n /= 5
        return result

Solution from kamyu104/LeetCode-Solutions · MIT