172. Factorial Trailing Zeroes -- 求n的阶乘末尾有几个0
2016-08-23 17:59
513 查看
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
(1)
(2)
Note: Your solution should be in logarithmic time complexity.
(1)
class Solution { public: int trailingZeroes(int n) { int ans = 0; for(long long i = 5; n / i; i *= 5) { ans += n / i; } return ans; } };
(2)
class Solution { public: int trailingZeroes(int n) { int ans = 0; while(n) { int t = n / 5; ans += t; n = t; } return ans; } };
相关文章推荐
- [LeetCode] 172. Factorial Trailing Zeroes 求阶乘末尾零的个数
- LeetCode 172. Factorial Trailing Zeroes (阶乘末尾零的数量)
- LeetCode 172. Factorial Trailing Zeroes(阶乘结果尾数0的个数)---E
- 172. Factorial Trailing Zeroes (计算n的阶乘尾部有多少个零)
- LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分
- leetcode 172. Factorial Trailing Zeroes(C语言,阶乘中尾数0的个数)26
- leetcode 172. Factorial Trailing Zeroes(阶乘尾后0个数)(因式分解)
- LightOJ 1138 - Trailing Zeroes (III)(二分&阶乘末尾0的个数)
- Factorial Trailing Zeroes 阶乘的后边有几个0
- LightOJ 1138 Trailing Zeroes (III) (阶乘末尾0的个数)
- [LeetCode] Factorial Trailing Zeroes 求阶乘末尾零的个数
- Java 计算N阶乘末尾0的个数-LeetCode 172 Factorial Trailing Zeroes
- leetcode解题之172# Factorial Trailing Zeroes Java版 (求n的阶乘末尾0的个数)
- 172. Factorial Trailing Zeroes计算n!末尾0的个数
- leetcode 172. Factorial Trailing Zeroes
- 172. Factorial Trailing Zeroes
- [LeetCode]172. Factorial Trailing Zeroes
- 172. Factorial Trailing Zeroes
- 172. Factorial Trailing Zeroes
- 【LeetCode-面试算法经典-Java实现】【172-Factorial Trailing Zeroes(阶乘尾后0的数目)】