[Lintcode] #2 尾部的零

来源:互联网 发布:淘宝号被限制了怎么办 编辑:程序博客网 时间:2024/05/18 12:31

设计一个算法,计算出n阶乘中尾部零的个数


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 count5 = 0;while (n > 0) {count5 += n / 5;n /= 5;}return count5;    }}


原创粉丝点击