Factorial Trailing Zeroes (java)

来源:互联网 发布:周涛 复杂网络 编辑:程序博客网 时间:2024/05/16 11:31

题目:

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

Note: Your solution should be in logarithmic time complexity.

java代码实现:

</pre><pre name="code" class="html">class Solution {        public int trailingZeroes(int n) {        int count = 0;        for (long i=5; n/i>=1; i *= 5)  //用int会有偏差          count += n/i;        return count;    }}

0 0
原创粉丝点击