172. Factorial Trailing Zeroes¶ Time: $O(\log_5 n)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6class Solution { public: int trailingZeroes(int n) { return n == 0 ? 0 : n / 5 + trailingZeroes(n / 5); } }; 1 2 3 4 5class Solution { public int trailingZeroes(int n) { return n == 0 ? 0 : n / 5 + trailingZeroes(n / 5); } } 1 2 3class Solution: def trailingZeroes(self, n: int) -> int: return 0 if n == 0 else n // 5 + self.trailingZeroes(n // 5)