关闭

【Leetcode】Factorial Trailing Zeroes

2843人阅读 评论(0) 收藏 举报
分类:

题目链接:https://leetcode.com/problems/factorial-trailing-zeroes/

题目:

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

Note: Your solution should be in logarithmic time complexity.

思路:

打印结果,然后找规律,发现每隔5个周期0的个数增一,隔5*5再上一轮的基础上再加一,直到5^x>=n。。。

事实上我做的 时候用leetcode的testcase上尝试打印了5、10、15...很容易发现规律..

算法:

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


2
0
查看评论

LeetCode(172) Factorial Trailing Zeroes

题目如下: Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 分析如下: 看上去简单,但是写出...
  • feliciafay
  • feliciafay
  • 2015-01-02 03:46
  • 6727

leetcode 172: Factorial Trailing Zeroes

Factorial Trailing Zeroes Total Accepted: 28 Total Submissions: 69 Given an integer n, return the number of trailing zeroes in n!. Note: Your solut...
  • xudli
  • xudli
  • 2014-12-30 09:54
  • 9528

【LeetCode-面试算法经典-Java实现】【172-Factorial Trailing Zeroes(阶乘尾后0的数目)】

【172-Factorial Trailing Zeroes(阶乘尾后0的数目)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】代码下载【https://github.com/Wang-Jun-Chao】原题  Given an integer n, return the nu...
  • DERRANTCM
  • DERRANTCM
  • 2015-08-23 06:43
  • 2562

172. Factorial Trailing Zeroes [easy] (Python)

题目链接https://leetcode.com/problems/factorial-trailing-zeroes/题目原文 Given an integer n, return the number of trailing zeroes in n!. Note: Your sol...
  • coder_orz
  • coder_orz
  • 2016-06-05 17:40
  • 1009

LeetCode Factorial Trailing Zeroes数学方法详解

Given an integer n, return the number of trailing zeroes in n!.题目的意思是要求一个整数的阶乘末尾有多少个0;1.需要注意的是后缀0是由2,5相乘得来,因此只需看有多少个2,5即可 n = 5: 5!的质因子中 (2 * 2 * 2 *...
  • taoyanqi8932
  • taoyanqi8932
  • 2016-08-05 15:14
  • 936

Leetcode: Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 解析: 只有2和...
  • doc_sgl
  • doc_sgl
  • 2015-01-02 21:23
  • 7121

Leetcode:172. Factorial Trailing Zeroes(JAVA)

【问题描述】 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time comple...
  • u010183658
  • u010183658
  • 2016-03-08 11:14
  • 218

[LeetCode] Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. cla...
  • zjjee
  • zjjee
  • 2014-12-31 15:25
  • 331

LeetCode -- Factorial Trailing Zeroes

LeetCode -- Factorial Trailing Zeroes
  • csharp25
  • csharp25
  • 2015-10-04 16:19
  • 892

LeetCode—Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 题目是...
  • xietingcandice
  • xietingcandice
  • 2015-01-28 11:37
  • 506
    个人资料
    • 访问:568186次
    • 积分:8667
    • 等级:
    • 排名:第2676名
    • 原创:305篇
    • 转载:6篇
    • 译文:0篇
    • 评论:37条
    博客专栏
    文章分类
    最新评论