当前位置:网站首页>模拟卷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,如果有错请留言,我看到了会修改的!谢谢!
边栏推荐
- Thinkphp5 frequently asked questions
- 数仓建模,什么是宽表?如何设计?好处与不足
- 5G服务化接口和参考点
- 【经验】通过跳板机远程连接内网服务器的相关配置
- CNN convolutional neural network
- 吴恩达老师机器学习课程笔记 00 写在前面
- Jetpack Compose 中的键盘处理
- Introduction to OSPF theory
- Hongke share | let you have a comprehensive understanding of "can bus errors" (IV) -- producing and recording can errors in practice
- 损失函数——交叉熵损失函数
猜你喜欢

Teacher wangshuyao's notes on operations research course 10 linear programming and simplex method (discussion on detection number and degradation)

SQL developer graphical window to create database (tablespace and user)

数据单位:位、字节、字、字长

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

C语言内存-栈与堆使用

MySQL 事物四种隔离级别分析

猜数字//第一次使用生成随机数

Actual combat! Talk about how to solve the deep paging problem of MySQL

成长为架构师途中的一些思考

循环神经网络RNN
随机推荐
没那么简单的单例模式
Base64与File之间的相互转化
Apisik health check test
Instant 新日期类的使用 API
王树尧老师运筹学课程笔记 05 线性规划与单纯形法(概念、建模、标准型)
Annotation
CNAME记录和A记录的区别
JMM memory model concept
基于Matlab解决线性规划问题
【技能积累】写邮件时的常用表达
PhantomReference 虚引用代码演示
数仓建模,什么是宽表?如何设计?好处与不足
pairs和ipairs的区别
Software definition boundary SDP
C language memory stack and heap usage
Use of callable
王树尧老师运筹学课程笔记 04 线性代数基础
矩阵分解与梯度下降
Shallow reading of reentrantlock source code of abstractqueuedsynchronizer (AQS)
SDN topology discovery principle