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的更多相关文章

  1. 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 ...

  2. 【LeetCode】172. Factorial Trailing Zeroes

    Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. Note: Your ...

  3. LeetCode Day4——Factorial Trailing Zeroes

    /* * Problem 172: Factorial Trailing Zeroes * Given an integer n, return the number of trailing zero ...

  4. LeetCode Factorial Trailing Zeroes Python

    Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. 题目意思: n求阶乘 ...

  5. LeetCode 172. 阶乘后的零(Factorial Trailing Zeroes)

    172. 阶乘后的零 172. Factorial Trailing Zeroes 题目描述 给定一个整数 n,返回 n! 结果尾数中零的数量. LeetCode172. Factorial Trai ...

  6. LeetCode_172. Factorial Trailing Zeroes

    172. Factorial Trailing Zeroes Easy Given an integer n, return the number of trailing zeroes in n!. ...

  7. [LeetCode] Factorial Trailing Zeroes 求阶乘末尾零的个数

    Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...

  8. LeetCode Factorial Trailing Zeroes

    原题链接在这里:https://leetcode.com/problems/factorial-trailing-zeroes/ 求factorial后结尾有多少个0,就是求有多少个2和5的配对. 但 ...

  9. [LeetCode] 172. Factorial Trailing Zeroes 求阶乘末尾零的个数

    Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...

随机推荐

  1. Ubuntu 18.04使用sudo pip3报错

    在使用sudo pip3 install python库的时候出现如下警告: The directory '/home/lzhu/.cache/pip/http' or its parent dire ...

  2. libunistring-0.9.9

    Introduction to libunistring Text files are nowadays usually encoded in Unicode, and may consist of ...

  3. Vue 核心之数据劫持

    前端界空前繁荣,各种框架横空出世,包括各类mvvm框架横行霸道,比如Angular.Regular.Vue.React等等,它们最大的优点就是可以实现数据绑定,再也不需要手动进行DOM操作了,它们实现 ...

  4. Eclipse中三种设置编码格式的方法

    转自:https://blog.csdn.net/rainy_black_dog/article/details/52403735 很早以前听过一位老师说过:咱们中国人不管学习哪种编程语言,总会遇到乱 ...

  5. JMeter3.2生成图形化HTML报告

    JMeter3.0引入了Dashboard Report,用于生成HTML页面格式图形化报告的扩展模块. 该模块支持通过两种方式生成多维度图形化测试报告: 在JMeter性能测试结束时,自动生成本次测 ...

  6. Golang的优雅重启

    更新(2015年4月):Florian von Bock已将本文中描述的内容转换为一个名为endless的优秀Go包 . 如果您有Golang HTTP服务,可能需要重新启动它以升级二进制文件或更改某 ...

  7. [maven] dependency标签理解

    在maven pom.xml文件中最多的就是dependency标签,我们用maven管理我们项目的依赖.这篇文章简单介绍dependency标签内部各个子标签的意义. 下面是dependency标签 ...

  8. Modbus库开发笔记:Modbus ASCII Master开发

    这一节我们来封装Modbus ASCII Master应用,Modbus ASCII主站的开发与RTU主站的开发是一致的.同样的我们也不是做具体的应用,而是实现ASCII主站的基本功能.我们将ASCI ...

  9. Confluence 6 诊断

    当你对性能进行诊断或者希望知道是什么原因导致 Confluence 崩溃,你希望知道在 Confluence 内部是什么导致这些问题发生的.这个时候系统的诊断信息能够帮助你获得更多的有关的这些信息. ...

  10. Confluence 6 编辑和删除用户宏

    编辑一个用户宏 希望对一个用户宏进行编辑: 进入  > 基本配置(General Configuration) > 用户宏(User Macros) 在相关的宏的边上,单击 编辑(Edit ...