首页 > 其他 > 详细

[leetcode]Factorial Trailing Zeroes

时间:2014-12-30 20:42:37      阅读:422      评论:0      收藏:0      [点我收藏+]

问题描述:

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;
    }


[leetcode]Factorial Trailing Zeroes

原文:http://blog.csdn.net/chenlei0630/article/details/42271019

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