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 ...
随机推荐
- SharePoint 2016 vs部署报错:无法加载功能xxx未能加载文件或程序集xxx或它的某一个依赖项。系统找不到指定的文件
环境描述: SharePoint 2016 单服务器场模式 开发工具:VS2017,项目类型(功能):计时器. 问题描述: 在用vs直接部署时,报错如下: 部署步骤"激活功能"中出 ...
- C++面向对象的特点
C++面向对象的特点 面向对象的特点主要有: 封装, 继承, 多态; 现在自己的简单理解如下, 但要明白具体怎么实现, 背后的原理是什么? 什么是封装, C++怎么实现封装 封装的大致可以分为: 函数 ...
- percona mysql5.7关闭审计功能方法
数据库的审计日志占用大量空间,当时是为了测试审计功能开启的,现在需要关闭 # /data/mysql_data]# du -sh * 124G audit.log # 查询审计相关参数 mysql&g ...
- Anaconda安装新模块
如果使用import导入的新模块没有安装,则会报错,下面是使用Anaconda管理进行安装的过程:1.打开Anaconda工具,如图: 2.可通过输入 conda list 查看已安装的模块 3.如果 ...
- iOS post提交数据有嵌套数组的处理方法
2017年11月21日17:11:43 解决办法, 修改iOS框架里的代码: http://www.jianshu.com/p/130daa0c2fe7 确实有效, 要不然, 内层的每一个键值对都会 ...
- MS SQL Server 建库建表
CREATE DATABASE Test use Test --创建用户类型表CREATE TABLE UserType ( ID INT NOT NULL identity(1,1) primary ...
- [swoole]swoole常见问题总汇
1.在daemon模式下Task异步任务写入文件需要采用绝对路径: 1.Task异步任务中操作数据库,如果仅仅只是在启动程序之初进行一次数据库链接,链接会在一定的时间后自动断开,应对这样的情况的最好办 ...
- c#在Excel指定单元格中插入图片
方法一: /// 将图片插入到指定的单元格位置,并设置图片的宽度和高度./// 注意:图片必须是绝对物理路径/// </summary>/// <param name="R ...
- Confluence 6 数据模型
本文档提供了 Confluence 的数据结构视图(schema )和数据模型概念上的的概述. 备注: Hibernate 的映射文件是针对 Confluence 数据模型的直接描述.在系统中的 Co ...
- MySQL数据库下载、安装
地址:https://www.mysql.com/ 解压下载的文件 配置环境变量 新建系统变量 变量名:MYSQL_HOME 变量值:解压 mysql-5.7.24-winx64.zip 后的路径 ...