当前位置:网站首页>模拟卷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,如果有错请留言,我看到了会修改的!谢谢!
边栏推荐
- 解决文件大导致磁盘满的问题
- 关于SQL Server语句入门级应用阶段性学习——找工作必备(一)
- Invalid access control
- vscode通过remotessh结合xdebug远程调试php解决方案
- STP spanning tree principle and example of election rules
- 王树尧老师运筹学课程笔记 04 线性代数基础
- 网络工具中的“瑞士军刀”-nc
- 数据库使用psql及jdbc进行远程连接,不定时自动断开的解决办法
- LDAP brief description and unified authentication description
- 数仓建模,什么是宽表?如何设计?好处与不足
猜你喜欢

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

【冷冻电镜|论文阅读】emClarity:用于高分辨率冷冻电子断层扫描和子断层平均的软件

Neuralcf neural collaborative filtering network

MySQL: what happens in the bufferpool when you crud? Ten pictures can make it clear

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

etcd原理

Share some tips for better code, smooth coding and improve efficiency

Understanding of access, hybrid and trunk modes

【讲座笔记】如何在稀烂的数据中做深度学习?

5G服务化接口和参考点
随机推荐
LDAP brief description and unified authentication description
N2 interface of 5g control plane protocol
【冷冻电镜|论文阅读】子断层平均 M 软件解读:Multi-particle cryo-EM refinement with M
猜数字//第一次使用生成随机数
分享一些你代码更好的小建议,流畅编码提搞效率
失效的访问控制
Shallow reading of condition object source code
CNAME记录和A记录的区别
【论文阅读】TomoAlign: A novel approach to correcting sample motion and 3D CTF in CryoET
10 frequently asked JVM questions in interviews
【冷冻电镜入门】加州理工公开课课程笔记 Part 3: Image Formation
Navicat for Oracle Cannot create oci environment
Loss function -- cross entropy loss function
IPv6 representation and configuration cases
CNN convolutional neural network
OpenResty的核心与cosocket
Actual combat! Talk about how to solve the deep paging problem of MySQL
C language memory stack and heap usage
【CryoEM】FSC, Fourier Shell Correlation简介
Computer right mouse click always turn around what's going on