[leetcode]Factorial Trailing Zeroes
时间:2014-12-30 20:42:37
收藏:0
阅读:424
问题描述:
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
基本思想
尾0的个数取决于5的个数。
代码:
int trailingZeroes(int n) { //C++
if(n <= 0)
return 0;
int num = 0;
int size;
while(n!=0){
size = n/5;
num += size;
n = size;
}
return num;
}原文:http://blog.csdn.net/chenlei0630/article/details/42271019
评论(0)