当前位置:网站首页>力扣(LeetCode)172. 阶乘后的零(2022.06.21)
力扣(LeetCode)172. 阶乘后的零(2022.06.21)
2022-06-22 07:43:00 【ChaoYue_miku】
给定一个整数 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/problems/factorial-trailing-zeroes
方法一:模拟
C++提交内容:
class Solution {
public:
int trailingZeroes(int n) {
int ans = 0;
while (n) {
n /= 5;
ans += n;
}
return ans;
}
};
边栏推荐
- Open source open source version - pintuan
- Target detection series -- detailed explanation of RCNN principle
- Major enterprises are losing money one after another. Where will the environmental protection industry go?
- The applet uses the step bar vant steps in vant
- Do you want to modify the title of the website
- Upload your own library to pod
- 【宋红康 MySQL数据库 】【高级篇】【06】MySQL的逻辑架构
- How to import Taobao products into another store
- Taobao assistant can not be used. How to export the baby in the warehouse to backup the data package
- 微信小游戏(四)
猜你喜欢
随机推荐
JS native implementation for loop rendering array
微信小游戏(三)
Invalid applet margin right, text overflow?
网站如何提高百度权重
Multimedia architecture -- Introduction to display
itertools 排列组合
Open version - account information synchronization and unification
Qualcomm platform LCM summary
Some problems caused by null data in MySQL
Wechat games (I)
CollectionViewCell
Use multithreading to speed up your crawler
8、 Slider assembly
Crmeb mall distribution function
phpcms手机门户网站配置
How to batch copy babies by sales volume in Taoying
Shutter margin negative margin
Get through version 4.3 mind map
Xlua environment configuration
【图论常见模板题】4种最短路解法和2种最小生成树解法









