[172] Factorial Trailing Zeroes
https://leetcode.com/problems/factorial-trailing-zeroes/description/
- algorithms
- Easy (36.97%)
- Source Code: 172.factorial-trailing-zeroes.py
- Total Accepted: 152.5K
- Total Submissions: 408.8K
- Testcase Example: '3'
Given an integer n, return the number of trailing zeroes in n!.
Example 1:
Input: 3 Output: 0 Explanation: 3! = 6, no trailing zero.
Example 2:
Input: 5 Output: 1 Explanation: 5! = 120, one trailing zero.
Note: Your solution should be in logarithmic time complexity.
python
class Solution(object):
def trailingZeroes(self, n):
"""
:type n: int
:rtype: int
"""
ans = 0
while n:
n /= 5
ans += n
return ans