7/29/2020

[LeetCode] 172. Factorial Trailing Zeroes

Problem : https://leetcode.com/problems/factorial-trailing-zeroes/

number of trailing zero = number of 10 
Because 2 * 5 = 10 and number of 5 is less than the number of 2.
This problem equals how many 5 in the given number.

class Solution:
    def trailingZeroes(self, n: int) -> int:
        return n // 5 + self.trailingZeroes(n // 5) if n > 0 else 0

No comments:

Post a Comment