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

Note: Your solution should be in logarithmic time complexity.

 

思路:编程之美里有,就是找因子5的个数。

int trailingZeroes(int n) {
        int ans = 0;
        while(n > 0)
        {
            ans += n / 5;
            n /= 5;
        }
        return ans;
    }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
  • 2021-06-07
  • 2021-09-05
  • 2021-08-22
  • 2021-06-03
猜你喜欢
  • 2021-04-02
  • 2021-09-01
  • 2021-11-02
  • 2021-06-22
  • 2022-02-20
  • 2021-05-20
相关资源
相似解决方案