172. Factorial Trailing Zeroes

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

Note that n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1.




def trailingZeroes(n: int):
       
    count = 0
    powerOfFive = 5
   
    while powerOfFive <= n:
        count = count + n // powerOfFive
        powerOfFive *= 5
       
    return count

Comments

Popular posts from this blog

849. Maximize Distance to Closest Person

347. Top K Frequent Elements

139. Word Break