首页 > 其他 > 详细

【LeetCode】Factorial Trailing Zeroes

时间:2015-01-05 07:07:14      阅读:346      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!