11! = 39916800, so the out should be 2

number / 5 is the total number of zeros.

class Solution {
public:
    /*
     * @param n: A long integer
     * @return: An integer, denote the number of trailing zeros in n!
     */
    long long trailingZeros(long long n) {
        // write your code here, try to do it without arithmetic operators.
        long long count = 0;
        long long number = n;
        while (number > 1) {
            number = number / 5;
            count += number;
        }
        return count;
    }
};

results matching ""

    No results matching ""