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语言 16进制与ascii码互转
/*把ASCII字符转换为16进制 */ uint8_t char_to_hex(const uint8_t *ch) { uint8_t value = 0; if(*ch >= 0 & ...
- LA 3263 (欧拉定理)
欧拉定理题意: 给你N 个点,按顺序一笔画完连成一个多边形 求这个平面被分为多少个区间 欧拉定理 : 平面上边为 n ,点为 c 则 区间为 n + 2 - c: 思路: 先扫,两两线段的交点,存下来 ...
- [PHP]一些坑
一.如果有一个字符串变量等于'error',它跟0 == 运算时,会返回true,但是它并不是一个预置常量 $test = 'error'; var_dump($test == 0);//true 二 ...
- awk-for循环简单用法
文本: [root@VM_0_84_centos ~]# cat sshd.txt 1 2 3 4 5 6 7 8 9 循环打印上述文本 for 循环的固定格式 i=1设置i的初始变量 i< ...
- 在线HTTP POST/GET接口测试工具 - aTool在线工具
百度搜索标题或直接访问网址如下 网址:http://www.atool.org/httptest.php 很好用的在线http get/post 测试工具
- js——字符串处理
字符串不能修改,所以修改后的结果都是以一个新的字符串返回,原串不改变 1. 创建字符串和typeof - 空字符串 var str = ""; - " ...
- iOS 高德地图轨迹回放的 思路, 及方法
// 开始,公司要求制作一段跑步轨迹 在地图上的 动画回放, 传入一段经纬度, 开始一想,这不是很简单吗, 高德地图有可以把经纬度转换成坐标点的方法 /** * @brief 将经纬度转换为指定vie ...
- ionic3 国际化
http://www.cnblogs.com/huangenai/p/6868173.html 按上面这个网站的步骤整一遍, 但是ionic3 会报错 所以 在 import { NgModule ...
- python --------------网络(socket)编程
一.网络协议 客户端/服务器架构 1.硬件C/S架构(打印机) 2.软件C/S架构(互联网中处处是C/S架构):B/S架构也是C/S架构的一种,B/S是浏览器/服务器 C/S架构与socket的关系: ...
- Python基础之初识类和对象
我们在前面学习了解了面向过程编程,接下来我们一起来学习一下面向对象编程.其实不管是面向过程,还是面向对 象,说白了就是一种编程方式而已.既然是面向对象编程,顾名思义,此编程方式的落地需要使用 “类” ...