题目:
给定一个整数 n,返回 n! 结果尾数中零的数量。
题解:
官方题解是不断除以5,知道n=0
我的想法略有不同,但也差不多:
class Solution:
def trailingZeroes(self, n: int) -> int:
x = 5
ans = 0
while n >= x:
ans += n // x
x = x * 5
return ans
题目:
给定一个整数 n,返回 n! 结果尾数中零的数量。
题解:
官方题解是不断除以5,知道n=0
我的想法略有不同,但也差不多:
class Solution:
def trailingZeroes(self, n: int) -> int:
x = 5
ans = 0
while n >= x:
ans += n // x
x = x * 5
return ans