leetcode 172 Factorial Trailing Zeroes
2016-06-19 14:16
274 查看
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
class Solution {
public:
int trailingZeroes(int n) {
if(n < 1) return 0;
int cnt = 0;
while(n >= 5) {
cnt += n/5;
n = n/5;
}
return cnt;
}
}
Note: Your solution should be in logarithmic time complexity.
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
class Solution {
public:
int trailingZeroes(int n) {
if(n < 1) return 0;
int cnt = 0;
while(n >= 5) {
cnt += n/5;
n = n/5;
}
return cnt;
}
}
相关文章推荐
- 4-3使用mailto在网页中链接Email地址
- Google人工智能平台TensorFlow介绍
- 关于AIDL一些需要注意的地方
- pybrain的安装及使用
- [bzoj1807] [Ioi2007]Pairs 彼此能听得见的动物对数
- 根据main函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数,使下面的程序能输出星号图:
- 线程间协作的两种方式:wait、notify、notifyAll和Condition
- 人工智能作业homework3——模拟退火解决TSP
- [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated c
- ORA-01804: failure to initialize timezone information
- 进程waitpid()的用法
- Failed to download samples index, please check your connection and try again
- 踩坑[INSTALL_FAILED_PERMISSION_LEVEL_DOWNGRADE]
- Develop -- Training(十四) -- 打印内容
- 关于PCA简单入门介绍
- 80老翁谈人生(5):人工智能与高考录取流程
- sublime package control 出现There are no packages available for installation
- 使用AIDL实现IPC通信之——实现服务端主动发送数据给客户端
- HDU 2925 Musical Chairs(约瑟夫环问题)
- 使用AIDL实现IPC通信之——简单调用远程服务的方法