LeetCode-172:Factorial Trailing Zeroes

来源:互联网 发布:淘宝联盟的pid是什么 编辑:程序博客网 时间:2024/05/16 14:14

原题描述如下:

Given an integer n, return the number of trailing zeroes inn!.

题意给定一个数字,判断该数字的阶乘共包含多少个0。

解题思路:

Java代码:

public class Solution {
    public int trailingZeroes(int n) {
        int res = 0;
        
        while(n != 0){
            n /= 5;
            res += n;
        }
        
        return res;
    }
}
0 0