当前位置:网站首页>模拟卷Leetcode【普通】172. 阶乘后的零
模拟卷Leetcode【普通】172. 阶乘后的零
2022-07-29 05:39:00 【邂逅模拟卷】
汇总:模拟卷Leetcode 题解汇总
172. 阶乘后的零
给定一个整数 n ,返回 n! 结果中尾随零的数量。
提示 n! = n * (n - 1) * (n - 2) * … * 3 * 2 * 1
示例 1:
输入:n = 3
输出:0
解释:3! = 6 ,不含尾随 0
示例 2:
输入:n = 5
输出:1
解释:5! = 120 ,有一个尾随 0
示例 3:
输入:n = 0
输出:0
提示:
0 <= n <= 104
进阶:你可以设计并实现对数时间复杂度的算法来解决此问题吗?
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/factorial-trailing-zeroes
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
代码:
from leetcode_python.utils import *
class Solution:
def trailingZeroes(self, n: int) -> int:
ans = 0
while n:
n //= 5
ans += n
return ans
def test(data_test):
s = Solution()
data = data_test # normal
# data = [List2Node(data_test[0])] # list转node
return s.getResult(*data)
def test_obj(data_test):
result = [None]
obj = Solution(*data_test[1][0])
for fun,data in zip(data_test[0][1::],data_test[1][1::]):
if data:
res = obj.__getattribute__(fun)(*data)
else:
res = obj.__getattribute__(fun)()
result.append(res)
return result
if __name__ == '__main__':
datas = [
[],
]
for data_test in datas:
t0 = time.time()
print('-'*50)
print('input:', data_test)
print('output:', test(data_test))
print(f'use time:{
time.time() - t0}s')
备注:
GitHub:https://github.com/monijuan/leetcode_python
CSDN汇总:模拟卷Leetcode 题解汇总
可以加QQ群交流:1092754609
leetcode_python.utils详见汇总页说明
先刷的题,之后用脚本生成的blog,如果有错请留言,我看到了会修改的!谢谢!
边栏推荐
猜你喜欢

JMM 内存模型概念

如何画出优秀的架构图

STP spanning tree principle and example of election rules

循环神经网络RNN

C language memory stack and heap usage

Embedding理解+代码

Hongke share | let you have a comprehensive understanding of "can bus errors" (IV) -- producing and recording can errors in practice

IDEA中实现Mapper接口到映射文件xml的跳转

损失函数——交叉熵损失函数

DM数据守护集群搭建
随机推荐
Teacher wangshuyao's notes on operations research 03 KKT theorem
10道面试常问JVM题
猜数字//第一次使用生成随机数
没那么简单的单例模式
关于SQL Server语句入门级应用阶段性学习——找工作必备(一)
Teacher wangshuyao's notes on operations research course 10 linear programming and simplex method (discussion on detection number and degradation)
Etcd principle
【解决方案】ERROR: lib/bridge_generated.dart:837:9: Error: The parameter ‘ptr‘ of the method ‘FlutterRustB
Huawei switch ce12808 import and export configuration file
Phantom reference virtual reference code demonstration
阿里一面,给了几条SQL,问需要执行几次树搜索操作?
王树尧老师运筹学课程笔记 03 KKT定理
SDN拓扑发现原理
王树尧老师运筹学课程笔记 08 线性规划与单纯形法(单纯形法)
Analysis of four isolation levels of MySQL things
【论文阅读 | 冷冻电镜】RELION 4.0 中新的 subtomogram averaging 方法解读
DBAsql面试题
【备忘】关于ssh为什么会失败的原因总结?下次记得来找。
Instant 新日期类的使用 API
Hongke share | let you have a comprehensive understanding of "can bus errors" (IV) -- producing and recording can errors in practice