n久不做题了 ,之前因为考研,然后又是假期,一直懒得做,今天开始吧
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
开始没有看到是阶乘,之后又研究复杂度的问题
代码如下:
class Solution {
public:
int trailingZeroes(int n) {
int count = 0;
for (;n > 4;)
{
n = n / 5;
count = count + n;
}
return count;
}
};本文出自 “不胖不瘦不丑不帅” 博客,转载请与作者联系!
【LeetCode】Factorial Trailing Zeroes
原文:http://jdmylove.blog.51cto.com/9688344/1599129