Factorial Trailing Zeroes Add to List
https://leetcode.com/problems/factorial-trailing-zeroes/#/description
想到了要找2x5;也想到了只要找5,剩下的2 管够。也想到了除以25 这种情况。然后却写出了TLE 的方案。。。。
要写出logn 的方案只需想到一点就是,不停的把5 的倍数,5x5 的倍数,5x5x5 的倍数等等数出来就行了
- /**
- * @param {number} n
- * @return {number}
- */
- var trailingZeroes = function(n) {
- var c = 0;
- var acc = 5;
- var end = false;
- while (1) {
- var a = parseInt(n / acc);
- if (a === 0) break;
- c += a;
- acc *= 5;
- }
- return c;
- };
Factorial Trailing Zeroes Add to List的更多相关文章
- LeetCode172 Factorial Trailing Zeroes. LeetCode258 Add Digits. LeetCode268 Missing Number
数学题 172. Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. N ...
- 【LeetCode】172. Factorial Trailing Zeroes
Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. Note: Your ...
- LeetCode Day4——Factorial Trailing Zeroes
/* * Problem 172: Factorial Trailing Zeroes * Given an integer n, return the number of trailing zero ...
- LeetCode Factorial Trailing Zeroes Python
Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. 题目意思: n求阶乘 ...
- LeetCode 172. 阶乘后的零(Factorial Trailing Zeroes)
172. 阶乘后的零 172. Factorial Trailing Zeroes 题目描述 给定一个整数 n,返回 n! 结果尾数中零的数量. LeetCode172. Factorial Trai ...
- LeetCode_172. Factorial Trailing Zeroes
172. Factorial Trailing Zeroes Easy Given an integer n, return the number of trailing zeroes in n!. ...
- [LeetCode] Factorial Trailing Zeroes 求阶乘末尾零的个数
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- LeetCode Factorial Trailing Zeroes
原题链接在这里:https://leetcode.com/problems/factorial-trailing-zeroes/ 求factorial后结尾有多少个0,就是求有多少个2和5的配对. 但 ...
- [LeetCode] 172. Factorial Trailing Zeroes 求阶乘末尾零的个数
Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...
随机推荐
- 【转】C++标准转换运算符static_cast
static_cast<new_type> (expression) 虽然const_cast是用来去除变量的const限定,但是static_cast却不是用来去除变量的static引用 ...
- oracle里面用sql做报表并带小计合计常用到的函数
1-- DECODE函数是Oracle PL/SQL是功能强大的函数之一,假设我们想给职员加工资,其标准是:工资在8000元以下的将加20%:工资在8000元以上的加15%,通常的做法是,先选出记录 ...
- HTTP连接池
<context:property-placeholder location="classpath:conf/framework/httpclient.properties" ...
- python深浅拷贝与赋值
初学编程的小伙伴都会对于深浅拷贝的用法有些疑问,今天我们就结合python变量存储的特性从内存的角度来谈一谈赋值和深浅拷贝~~~ 预备知识一——python的变量及其存储 在详细的了解python中赋 ...
- winform无需安装pdf阅读器打开pdf文件
控件来源:http://www.o2sol.com/pdfview4net/download.htm (使用版本:2016年8月31号更新版) 备份链接: https://pan.baidu.com/ ...
- 暑假里的第八篇Java
日期:2018.9.1 博客期:008 星期六 这几天刚到学校,Java方面写的少了!目前在做老师头放假前发布的那一套题目,就是哪个Java程序测试卷.至于自己能不能都做出来我自己心里十分清楚!今天就 ...
- 一.定时任务详解https://i.cnblogs.com/EditPosts.aspx
定时任务的详解 h每小时运行 d每天运行 w每周运行 m每个月运行 中毒时查看系统定时任务是否有病毒的脚本. crontab -l 查看用户的定时任务 crontab -e 进入编辑界面增加 ...
- 高并发编程基础Synchronized与Volatile
关键字Synchronized: 当使用Synchrnized (o) ,锁定 o 的时候,锁定的是 o 指向的堆内存中 new 出来的对象,而非 o 引用,当锁定 o 以后,一旦 o 指向了其他对象 ...
- Python实操
有两个列表,分别存放报名学习linux和python课程的学生名字 linux=['钢弹','小壁虎','小虎比','alex','wupeiqi','yuanhao'] python=['drago ...
- mybatis常见错误总结
1. 现象:mybatis xml文件中查询的返回类型写成list或java.util.List时,执行sql时报 java.lang.UnsupportedOperationException错误. ...