172. Factorial Trailing Zeroes -- 求n的阶乘末尾有几个0
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
(1)
class Solution {
public:
int trailingZeroes(int n) {
int ans = ;
for(long long i = ; n / i; i *= )
{
ans += n / i;
}
return ans;
}
};
(2)
class Solution {
public:
int trailingZeroes(int n) {
int ans = ;
while(n)
{
int t = n / ;
ans += t;
n = t;
}
return ans;
}
};
172. Factorial Trailing Zeroes -- 求n的阶乘末尾有几个0的更多相关文章
- [LeetCode] 172. Factorial Trailing Zeroes 求阶乘末尾零的个数
Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...
- 【LeetCode】172. Factorial Trailing Zeroes
Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. Note: Your ...
- [LeetCode] Factorial Trailing Zeroes 求阶乘末尾零的个数
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- Java 计算N阶乘末尾0的个数-LeetCode 172 Factorial Trailing Zeroes
题目 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...
- ✡ leetcode 172. Factorial Trailing Zeroes 阶乘中的结尾0个数--------- java
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- 172. Factorial Trailing Zeroes(阶乘中0的个数 数学题)
Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...
- LeetCode 172. Factorial Trailing Zeroes (阶乘末尾零的数量)
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- 【一天一道LeetCode】#172. Factorial Trailing Zeroes
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- Java [Leetcode 172]Factorial Trailing Zeroes
题目描述: Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be ...
随机推荐
- 5.Primitive, Reference, and Value Types
1.Programming Language Primitive Types primitive types:Any data types the compiler directly supports ...
- ALV详解:OO SALV
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- [Effective Java]第六章 枚举和注解
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- poj 2398 (叉积+二分)
http://poj.org/problem?id=2398 Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...
- FZU 2221 RunningMan(跑男)
Problem Description 题目描述 ZB loves watching RunningMan! There's a game in RunningMan called 100 vs 10 ...
- SQL - 批量修改表中所有行数据某字段的部分内容
UPDATE 表名 SET 字段名 = REPLACE (字段名, 'old', 'new');
- c 函数调用产生的汇编指令和数据在内存情况(2)
c 函数调用产生的汇编指令和数据在内存情况(1) 一直对函数调用的具体汇编指令和各种变量在内存的具体分配,一知半解.各种资料都很详细,但是不实践,不亲自查看下内存总不能笃定.那就自己做下. 两个目的: ...
- mysql /*! 50100 ... */ 条件编译
1./*...*/ 是注释,mysql不会执行.2.mysql对标准sql进行了扩展,包含了一些自己的特性.3./*!...*/ 是一种特殊的注释,其他的数据库产品当然不会执行.mysql特殊处理,会 ...
- Android 设置进度条背景
Android 设置进度条背景 直接上代码 <ProgressBar android:id="@+id/progressBar" android:layout_width=& ...
- Android 图片Exif信息相关的获取与修改
1 Exif是什么 Exif是一种图像文件格式,它的数据存储于JPEG格式是完全相同的,实际上Exif格式就是JPEG格式头插入了 数码照片的信息,包括拍摄的光圈.快门.平衡白.ISO.焦距.日期时间 ...