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 ...
随机推荐
- ssdb主从及双主模型配置和简单管理
ssdb主从及双主模型配置和简单管理 levelDB是一个key->value 的数据存储库,其只能在本地保存数据,支持持久化,并且支持保存非常大的数据,单机redis在保存较大数据的时候数十G ...
- go import 使用方法记录
import "fmt" 最常用的一种形式 import "./test" 导入同一目录下test包中的内容 import f "fmt ...
- python学习第6天
id is == 代码块 代码块的缓存机制 小数据池(不同代码块的缓存机制) 小数据池(驻留机制)总结 数据类型之间的转换 int bool str 三者转化是可以的. bool 可以与所有的数据类 ...
- 使用Gitblit 在Windows上部署Git Server
Windows平台下Git服务器搭建 首先要下载Java JDK,安装完成后设置环境变量,先把java环境配好,接下来才是下面的gitblit.关于java环境配置请看上一篇文章 gitblit下载 ...
- tomcat占用cpu比较多
在Linux中当Tomcat启动后,我们只是去查看应用是否能够正常访问来判断Tomcat启动是否正常.一般情况下这样看是没有问题的,但是有时候我们会发现当Tomcat使用了一段时间后,开始出现CPU或 ...
- -bash: /opt/cslc/jdk1.8.0_144/bin/jps: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录
yum install -y glibc.i686 解决问题
- liunx 安装 mysql 5.6
第一步 解压文件 目录切换到/usr/local/ cd /usr/local/ 解压 tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz 重命名为 ...
- iOS -- Effective Objective-C 阅读笔记 (3)
1: 理解 属性 的概念 属性会自动生成存取方法, 可以利用点语法调用, 若不想编译器自动合成存取方法, 可以自己实现, 还有另外一种方法, 就是使用 @dynamic 关键字, 它会告诉编译器, ...
- vue element-UI 升级报错Cannot find module "element-ui/lib/theme-default/index.css"
饿了么 用之前的版本 有些组件跟api 不一样了所以更新了最新的版本,发现 报一堆错误 主要错误是这个 Cannot find module "element-ui/lib/theme-de ...
- vue-cli脚手架(框架)
一.创建vue项目 npm install vue-cli -g #-g全局 (sudo)npm install vue-cli -g #mac笔记本 vue-init webpack myvue # ...