首页 > 其他 > 详细

LintCode 2. 尾部的零

时间:2018-05-02 15:07:51      阅读:224      评论:0      收藏:0      [点我收藏+]

题目:

  • LintCode 2. 尾部的零
  • 设计一个算法,计算出n阶乘中尾部零的个数。

样例:

  • 11! = 39916800,因此应该返回 2

思路:

实现

  • Java实现代码

    public class Solution {
    /*
     * @param n: An integer
     * @return: An integer, denote the number of trailing zeros in n!
     */
    public long trailingZeros(long n) {
            // write your code here, try to do it without arithmetic operators.
            long sum = 0;
            while(n>0){
                n=n/5;
                sum=sum+n;
            }
            return sum;
        }
    }

LintCode 2. 尾部的零

原文:https://www.cnblogs.com/hglibin/p/8979497.html

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