- leetcode:172. Factorial Trailing
- [String]172. Factorial Trailing
- LeetCode 172. Factorial Trailing
- Leetcode 172. Factorial Trailing
- LeetCode 172. Factorial Trailing
- Leetcode 172. Factorial Trailing
- 172. Factorial Trailing Zeroes
- [刷题防痴呆] 0172 - 阶乘后的零 (Factorial
- 2022-03-25 「172. 阶乘后的零」
- 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.
思路:最后的0有多少个取决于阶乘累加的过程中有多少个2*5,而2出现的概率要大于5,所以只需要统计5的个数。
public int trailingZeroes(int n) {
int res = 0;
while (n > 0) {
n /= 5;
res += n;
}
return res;
}
网友评论