您的位置:首页 > 大数据 > 人工智能

LeetCode题解:Factorial Trailing Zeroes

2015-08-26 20:39 567 查看
Given an integer n, return the number of trailing zeroes in n!.

题意:求n阶乘结果中有多少0

解决思路:阶乘要出现0必然能分解为5*2,2的数量大于5的数量,所以每一个5必然有一个2匹配,所以计算5的个数即可

代码:

public class Solution {
    public int trailingZeroes(int n) {
        int count = 0;
        while(n > 0){
            n /= 5;
            count += n;
        }

        return count;
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: