Computer science note/LeetCode

Factorial Trailing Zeroes

problem description and solution for Factorial Trailing Zeroes problem on LeetCode

LeetCode - The World's Leading Online Programming Learning Platform
Given an integer n, return the number of trailing zeroes in n!.
给定一个整数 n ,返回 中 n! 尾随零的个数。

Note that n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1. 请注意。 n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1

Example 1: 示例 1:

Input: n = 3 Output: 0 Explanation: 3! = 6, no trailing zero.

Example 2: 示例 2:

Input: n = 5 Output: 1 Explanation: 5! = 120, one trailing zero.

Example 3: 例3:

Input: n = 0 Output: 0

Constraints: 约束:

  • 0 <= n <= 104

Follow up: Could you write a solution that works in logarithmic time complexity?
追问:你能写一个对数时间复杂度的解决方案吗?