leetcode:数学:Factorial Trailing Zeroes(172)

来源:互联网 发布:sql更改语句 编辑:程序博客网 时间:2024/06/05 00:14

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

Note: Your solution should be in logarithmic time complexity.


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