[leetcode] Factorial Trailing Zeroes

Factorial Trailing Zeroes

#include <iostream>
using namespace std;

class Solution {
public:
    int trailingZeroes(int n) {
        
        if (n<5) {
            return 0;
        }
        
        int res=0;
        while (n) {
            n/=5;
            res+=n;
        }
        
        return res;
    }
};

int main(){
    Solution so;
    int num=25;
    cout<<so.trailingZeroes(num)<<endl;
    return 0;
}


你可能感兴趣的:([leetcode] Factorial Trailing Zeroes)