Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
Method 2 is original by myself. It is very close to Method 1, i need think more deeply.
Method 1 is taken from another programmer.
Method 1:
public class Solution {
public int trailingZeroes(int n) {
int count = 0;
while(n > 0){
count = count + (n /= 5);
}
return count;
}
}
Method 2:
public class Solution {
public int trailingZeroes(int n) {
int count = 0;
int index = 5;
int flag = 5;
while(n >= flag){
count = count + (n / flag);
flag = flag * index;
}
return count;
}
}