[LeetCode]172 阶乘后的零

题目描述

给定一个整数 n,返回 n! 结果尾数中零的数量。

示例1

输入: 3
输出: 0
解释: 3! = 6, 尾数中没有零。

示例2

输入: 5
输出: 1
解释: 5! = 120, 尾数中有 1 个零.

代码

1
2
3
4
5
6
7
8
9
10
11
class Solution(object):
def trailingZeroes(self, n):
"""
:type n: int
:rtype: int
"""
res = 0
while n > 0:
n = n/5
res += n
return res