刷一题Leetcode:Factorial Trailing Zeroes
2015-08-31 16:51
537 查看
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.
就是返回 n! 这个数里“零的个数”
Note: Your solution should be in logarithmic time complexity.
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
就是返回 n! 这个数里“零的个数”
[code]public class Solution { public int trailingZeroes(int n) { int result = 0; if (n < 0) { return -1; } else if (n < 5) { return 0; } else { while (n != 0) { n = n/5; result += n; } } return result; } }
相关文章推荐
- LeetCode之Contains Duplicate
- OC之非ARC环境下循环retain问题
- HDU 2476 String painter(区间dp)
- c的Main函数参数解析
- poj 1273 Drainage Ditches
- leecode 每日解题思路 127-Factorial Trailing Zeroes
- (null): Linker command failed with exit code 1 (use -v to see invocation)
- 为什么要内存对齐 Data alignment: Straighten up and fly right
- INSTALL_FAILED_CONFLICTING_PROVIDER错误解决方法
- 将 paired count 和unpaired count 相加
- rust用struct保存特定trait的引用
- 不同RAID模式的优缺点
- win7旗舰版卸载“获取Windows10”升级助手
- leetcode 172 Factorial Trailing Zeroes(难易度:Easy)
- 详解C语言中的wait()函数和waitpid()函数
- 【LeetCode】70. Climbing Stairs
- [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)错误原因
- Linux线程-互斥锁pthread_mutex_t http://blog.csdn.net/zmxiangde_88/article/details/7998458
- 减少页面回流与重绘(Reflow & Repaint)
- foxmail邮箱 邮件地址信息 以及邮件内容信息的导入导出