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
Post a Comment