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