【LeetCode】Factorial Trailing Zeroes

时间:2015-01-05 07:07:14   收藏:0   阅读:346

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;

    }

};

本文出自 “不胖不瘦不丑不帅” 博客,转载请与作者联系!

原文:http://jdmylove.blog.51cto.com/9688344/1599129

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!