172. Factorial Trailing Zeroes
2016-05-23 10:13
661 查看
172. Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.
Analysis:
参考:http://bookshadow.com/weblog/2014/12/30/leetcode-factorial-trailing-zeroes/ 和 http://www.cnblogs.com/ganganloveu/p/4193373.html
两个其实说的是一个意思,一种方法。
Source Code(C++):
#include <iostream> #include <vector> #include <algorithm> using namespace std; class Solution { public: int trailingZeroes(int n) { int five_counts=0; while(n>0) { five_counts += n/5; n /= 5; } return five_counts; } }; int main() { Solution sol; cout << sol.trailingZeroes(50); return 0; }
相关文章推荐
- AIDL进程间调用与Binder的简单介绍
- Run-Time Check Failure #2分析
- 人工智能:医用机器人能否为医生减少工作负担?
- LightOJ 1138 Trailing Zeroes (III)(二分)
- LeetCode No336. Palindrome Pairs
- Task and Await: Consuming Awaitable Methods
- 【CodeVS3098】badhair
- AIDL的小demo
- LeetCode OJ 11. Container With Most Water
- 软raid创建及详细参数
- socketpair函数详解
- container_of宏
- hdu 1151 Air Raid【最小路径覆盖】
- FAILED: InvalidConfigurationException hive.server2.authentication can't be none in non-testing mode
- main方法的理解
- uva1450-Airport
- TensorFlow人工智能引擎入门教程所有目录
- map与vector---Email Aliases
- 人工智能之机器学习常见算法
- 安装CENTOS 6.5 32位(CentOS-6.5-i386)+postfix+dovecot+openwebmail passwd验证的邮件系统