> For the complete documentation index, see [llms.txt](https://code-snippets.hbamithkumara.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-snippets.hbamithkumara.com/leetcode/problems/101-200/factorial-trailing-zeroes.md).

# 172. Factorial Trailing Zeroes

### Description

Given an integer `n`, return *the number of trailing zeroes in `n!`*.

Could you write a solution that works in logarithmic time complexity?

### Constraints

* `1 <= n <= 104`

### Approach

### Links

* [GeeksforGeeks](https://www.geeksforgeeks.org/count-trailing-zeroes-factorial-number/)
* [Leetcode](https://leetcode.com/problems/factorial-trailing-zeroes/)
* [ProgramCreek](https://www.programcreek.com/2014/04/leetcode-factorial-trailing-zeroes-java/)
* [YouTube](https://youtu.be/3Hdmv_Ym8PI)

### **Examples**

{% tabs %}
{% tab title="Example 1" %}
**Input:** n = 3

**Output:** 0

**Explanation:** 3! = 6, no trailing zero.
{% endtab %}

{% tab title="Example 2" %}
**Input:** n = 5

**Output:** 1

**Explanation:** 5! = 120, one trailing zero.
{% endtab %}

{% tab title="Example 3" %}
**Input:** n = 0

**Output:** 0
{% endtab %}
{% endtabs %}

### **Solutions**

{% tabs %}
{% tab title="Solution 1" %}

```java
/**
 * Time complexity : 
 * Space complexity : 
 */

class Solution {
    public int trailingZeroes(int n) {
        if(n <= 0) return 0;
        
        int count = 0;
        for(int i = 5; n/i >= 1; i *= 5) {
            count += n/i;
        }
        
        return count;
    }
}
```

{% endtab %}
{% endtabs %}

### **Follow up**

*
