算法 n!的0

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

AAAA:

class Solution {
public:
    int trailingZeroes(int n) {
        int tem = 0;
        int count = 0;
        while(n){
            tem = n/5;
            count += tem;
            n = tem;
        }
        return count; 
    }
};

点赞