Leetcode 172.阶乘后的零

阶乘后的零

给定一个整数 n,返回 n! 结果尾数中零的数量。

示例 1:

输入: 3

输出: 0

解释: 3! = 6, 尾数中没有零。

示例 2:

输入: 5

输出: 1

解释: 5! = 120, 尾数中有 1 个零.

 1 class Solution {
 2     public static int trailingZeroes(int n) {
 3         int sum=0;
 4         while(n>0){
 5             sum+=n/5;
 6             n/=5;
 7         }
 8         return sum;
 9     }
10     public static void main(String[] args){
11         trailingZeroes(25);
12     }
13 }
原文地址:https://www.cnblogs.com/kexinxin/p/10202983.html