/*****************************************************问题描述*************************************************
Given a column title as appear in an Excel sheet, return its corresponding column number.
Given an integer n, return the number of trailing zeroes in n!.
Example 1:
Input: 3
Output: 0
Explanation: 3! = 6, no trailing zero.
Example 2:
Input: 5
Output: 1
Explanation: 5! = 120, one trailing zero.
给定一个整数,求它的阶乘数值后面0的个数.
/*****************************************************我的解答*************************************************
//就是求n!中因子5的个数
/**
* @param {number} n
* @return {number}
*/
var trailingZeroes = function(n) {
var fiveNum = function(num){
var count = 0;
if(num % 5 != 0)
{
return 0;
}
else
{
do
{
count++;
num = num / 5;
}while(num % 5 == 0);
}
return count;
};
var countAll = 0;
for(var index = 1; index <= n; index++)
{
countAll += fiveNum(index);
}
return countAll;
};
console.log(trailingZeroes(1000));
leetCode刷题记录28_172_Factorial Trailing Zeroes
猜你喜欢
转载自blog.csdn.net/gunsmoke/article/details/87882799
今日推荐
周排行