Factorial Trailing Zeroes

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

题目意思:

n求阶乘以后,其中有多少个数字是以0结尾的。

方法一:

class Solution:
# @return an integer
def trailingZeroes(self, n):
res = 0
if n < 5:
return 0
else:
return n/5+ self.trailingZeroes(n/5)

方法二:

class Solution:
# @return an integer
def trailingZeroes(self, n):
res = 0
x = 5
while( n >= x):
res += n/x
x *= 5
return res

参考博文:http://www.tuicool.com/articles/RZZnQf

n!后缀0的个数 = n!质因子中5的个数 = floor(n/5) + floor(n/25) + floor(n/125) + ....

LeetCode Factorial Trailing Zeroes Python的更多相关文章

  1. [LeetCode] Factorial Trailing Zeroes 求阶乘末尾零的个数

    Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...

  2. LeetCode Factorial Trailing Zeroes

    原题链接在这里:https://leetcode.com/problems/factorial-trailing-zeroes/ 求factorial后结尾有多少个0,就是求有多少个2和5的配对. 但 ...

  3. 关于[LeetCode]Factorial Trailing Zeroes O(logn)解法的理解

    题目描述: Given an integer n, return the number of trailing zeroes in n!. 题目大意: 给定一个整数n,返回n!(n的阶乘)结果中后缀0 ...

  4. [LeetCode] Factorial Trailing Zeroes 阶乘末尾0

    Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...

  5. Python3解leetcode Factorial Trailing Zeroes

    问题描述: Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 ...

  6. LeetCode Factorial Trailing Zeroes (阶乘后缀零)

    题意:如标题 思路:其他文章已经写过,参考其他. class Solution { public: int trailingZeroes(int n) { <? n/: n/+trailingZ ...

  7. LeetCode 172. 阶乘后的零(Factorial Trailing Zeroes)

    172. 阶乘后的零 172. Factorial Trailing Zeroes 题目描述 给定一个整数 n,返回 n! 结果尾数中零的数量. LeetCode172. Factorial Trai ...

  8. 【LeetCode】172. Factorial Trailing Zeroes

    Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. Note: Your ...

  9. LeetCode Day4——Factorial Trailing Zeroes

    /* * Problem 172: Factorial Trailing Zeroes * Given an integer n, return the number of trailing zero ...

随机推荐

  1. LeetCode--027--移除元素

    问题描述: 给定一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间 ...

  2. android------锁屏(手机启动出现锁屏界面)

    以前用过一个红包锁屏的软件,第一次打开手机出现锁屏,滑动领取收益,当时觉得这功能不错,就查阅资料,写了一个案例, apk运行流程: 进入软件--->启动服务--->关闭手机(可先退出应用) ...

  3. 『TensotFlow』RNN/LSTM古诗生成

    往期RNN相关工程实践文章 『TensotFlow』基础RNN网络分类问题 『TensotFlow』RNN中文文本_上 『TensotFlow』基础RNN网络回归问题 『TensotFlow』RNN中 ...

  4. Tips for Sync Vimtex and PDF

    vimtex synctex: \lv. skim synctex: to display the TeX source line corresponding to a point in the PD ...

  5. secureCRT启动xmanager图形化工具

    secureCRT启动xmanager图形化工具 2014年9月17日 11:42 secureCRT是我们在维护UNIX或者linux的重要工具.xmanager 工具是连接UNIX或者linux的 ...

  6. ASP.NET MVC 习惯

  7. 使用UTL_SMTP发送中文邮件及使用UTL_TCP从附件服务器获取中文附件

    先上最重要的干货 发送邮件正文及主题的时候一定要使用convert重新编码 主题: utl_smtp.write_raw_data(l_mail_conn, utl_raw.cast_to_raw(c ...

  8. Python简单网页爬虫——极客学院视频自动下载

    http://blog.csdn.net/supercooly/article/details/51003921

  9. 用Maven创建第一个web项目

    http://www.cnblogs.com/leiOOlei/p/3361633.html 一.创建项目 1.Eclipse中用Maven创建项目 上图中Next 2.继续Next 3.选maven ...

  10. 蓝桥杯—ALGO-18 单词接龙(DFS)

    问题描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母, 要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中出现两次) ,在两个单词相连时,其 ...