# [172\. Factorial Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes/) 找階層 $n!$ 的尾端有多少個 `0`,也就是找 `10` 的個數,但因為 `2` 太多了,所以找有多少個 `5` 就好 :::spoiler Solution ```cpp= class Solution { public: int trailingZeroes(int n) { int res = 0; while (n) { res += n / 5; n /= 5; } return res; } }; ``` - 時間複雜度:$O(n)$ - 空間複雜度:$O(1)$ :::
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up