Lintcode:尾部的零
来源:互联网 发布:电子相册制作软件知乎 编辑:程序博客网 时间:2024/05/04 19:05
设计一个算法,计算出n阶乘中尾部零的个数
样例
11! = 39916800,因此应该返回 2
python:
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. if n == 0: return 1; x = 0 while n > 5: x += n // 5 n = n // 5 return x
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. if (n == 0) { return 1; } if(n > 0 && n < 5) { return 0; }else{ return (n/5 + trailingZeros(n/5)); } }};
阅读全文
0 0
- LintCode 尾部的零
- lintcode ---- 尾部的零
- LintCode : 尾部的零
- Lintcode 尾部的零
- LintCode:尾部的零
- Lintcode:尾部的零
- Lintcode 尾部零的个数
- LintCode 2 尾部的零
- LintCode Python 尾部的零
- LintCode 2.尾部的零
- 【LintCode】2、尾部的零
- [Lintcode] #2 尾部的零
- LintCode-(2)尾部的零
- Lintcode 2: 尾部的零
- LintCode 2. 尾部的零
- Lintcode 2. 尾部的零
- lintcode 2:尾部的零
- LintCode Trailing Zeros 尾部的零
- jvm参数详解
- linux下mysql的root密码忘记解决方
- 在ubuntu中安装单机Hadoop(三)
- 坑爹的Android Ble问题记录日志
- 使用 phantomjs 异步爬取 ajax 网页数据
- Lintcode:尾部的零
- PyTorch学习总结(二)——基于torch.utils.ffi的自定义C扩展
- Linux下swoole环境搭建
- Linux如何查看当前占用CPU或内存最多的几个进程
- 关于WEBSERVICE的Connection reset异常
- 小学奥数思维训练题(十一)
- 目标检测标注工具labelImg使用方法
- spring-boot 学习之路
- JCVideoPlayerStandard的视频播放