leetcode:Factorial Trailing Zeroes
2015-07-15 22:46
441 查看
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
class Solution { public: int trailingZeroes(int n) { int cnt = 0; /*long long i = 5;//之前一直TLE 是因为把i的类型定义成整型,这样当n为整型最大值时,i乘以5将会超出整型范围变成负数,这样n除以i将不会为0而陷入死 //循环,后来发现其实i的定义纯属多余,以后一定要注意细节 while(n / i) { cnt += n / i; i *= 5; }*/ while(n) { cnt += n / 5; n /= 5; } return cnt; } };
相关文章推荐
- baiducloud go through
- XeTeX: “Failed to convert input string to UTF16″
- LeetCode(11) Container With Most Water
- linxu的RAID技术
- 太晚睡觉等于自杀http://blog.csdn.net/augusdi/article/details/5440987
- STL中容器的erase()
- CLOSE-WAIT与TIME_WAIT
- 关于keepalived执行后日志狂刷IPVS: Can't initialize ipvs: Protocol not available的问题
- Change the log files location of a WebLogic Domain
- 杭电1145 so you want to be a 2n-aire?
- 内存管理: alloc, retain, release, autorelease, copy, assign
- pthread_cond_wait的理解
- 内存管理(一):栈区、堆区,成员变量和局部变量,alloc,retain,自动释放池,成员变量及属性的内存管理
- liunx GHOST clonezilla(再生龙)UltraISO刻录问题
- 解决Robotium测试中Installation error INSTALL_FAILED_VERSION_DOWNGRADE错误
- Communications Link failure
- 关于android.intent.action.MAIN与android.intent.category
- 2013 Multi-University Training Contest 4
- 通过手机页面获取当前城市
- Rails4 中 因为secret key 引起在production环境下无法运行