[InterviewBit] Trailing Zeros in Factorial

Trailing Zeros in Factorial

  • Time :
  • Space :
1
2
3
4
5
6
7
8
int Solution::trailingZeroes(int A) {
int res = 0;
for(int i = 5; i <= A; i *= 5) {
res += A / i;
}
return res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/09/21/PS/interviewbit/trailing-zeros-in-factorial/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.