题解 | #阶乘末尾0的数量#

阶乘末尾0的数量

http://www.nowcoder.com/practice/aa03dff18376454c9d2e359163bf44b8

import java.util.*;

//暴力解法:时间复杂度大,超时

 public class Solution {

/**
 * the number of 0
 * @param n long长整型 the number
 * @return long长整型
 */
public long thenumberof0 (long n) {
    // write code here
    //特殊值处理
    if(n == 0){
        return 0;
    }
    
    long m = 1;
    //求阶乘
    for(long i=1;i<=n;i++){
        m = m*i;
    }
    
    //求个数
    int count = 0;
    long remainder = m%10;
    long temp = m/10;
    while(remainder==0){
        count++;
        remainder = temp%10;
        temp = temp/10;
    }
    
    return count;
}

}

全部评论

相关推荐

群星之怒:不是哥们,你就不好奇瘫痪三十年的老植物人是啥样的吗?
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务