首页
mac
it
登录
6mi
u
盘
搜
搜 索
it
172. 阶乘后的零
172. 阶乘后的零
mac
2024-04-18
30
题目: 给定一个整数 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
转载请注明原文地址: https://mac.8miu.com/read-489843.html
最新回复
(
0
)