Lintcode 2: 尾部的零
来源:互联网 发布:python mysql模块安装 编辑:程序博客网 时间:2024/05/23 16:53
设计一个算法,计算出n阶乘中尾部零的个数
解析:仔细分析这个题,n!=1*2*,,,,,*n要产生0,就要有5,但是坑就在有25,125,,,,,这种多个5组成,考虑这个就ok啦。燃鹅人老了,忘了把计数器定义成long long类型。
c++版本:
class Solution {public: /* * @param n: A long integer * @return: An integer, denote the number of trailing zeros in n! */long long trailingZeros(long long n) {// write your code here, try to do it without arithmetic operators.long long count = 0;while (n>0){ n=n/5;count =count+ n;}return count;}};
class Solution: """ @param: n: An integer @return: An integer, denote the number of trailing zeros in n! """ def trailingZeros(self, n): # write your code here, try to do it without arithmetic operators. count=0 while n>0: n=n/5 count+=n return count
阅读全文
0 0
- LintCode 2 尾部的零
- 【LintCode】2、尾部的零
- [Lintcode] #2 尾部的零
- LintCode-(2)尾部的零
- Lintcode 2: 尾部的零
- lintcode 2:尾部的零
- LintCode 尾部的零
- lintcode ---- 尾部的零
- LintCode : 尾部的零
- Lintcode 尾部的零
- LintCode:尾部的零
- Lintcode:尾部的零
- LintCode题解(2)--尾部的零
- (lintcode)第2题尾部的零
- LintCode之2 尾部的零
- LintCode 2 : 尾部的零(java实现)
- Lintcode 尾部零的个数
- LintCode Python 尾部的零
- Statgraphics Centurion v18.1.01官方版下载附安装教程
- OpenCV组件学习
- 结构体排序
- php简易表单
- Java Synchronized的用法
- Lintcode 2: 尾部的零
- MAC FreeVPN
- Java CAS 和ABA问题
- BZOJ3833: [Poi2014]Solar lamps
- 替换给定字符数组的空格
- 使用apache反代tomacat
- Oil Skimming HDU
- docker搭建kafka
- Simplify Path:字符串的修改匹配