172. Factorial Trailing Zeroes

题目:

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

Note: Your solution should be in logarithmic time complexity.

链接: http://leetcode.com/problems/factorial-trailing-zeroes/

2/21/2017

错误:

1. 此题只需要算5,如果算2的话有错误,第7行会出现除0的情况,估计是溢出错误

2. 正确解法是n/5,base*5的情况会有错,错误例子是输入1808548329,输出452137078,而正确答案应该是452137076。原因?

 1 public class Solution {
 2     public int trailingZeroes(int n) {
 3         int n1 = 0;
 4         int base1 = 5;
 5 
 6         while (n > 0) {
 7         n1 += n / base1;
 8             n /= base1;
 9         }
10         return n1;
11     }
12 }

 

posted @ 2017-02-22 02:23  panini  阅读(127)  评论(0编辑  收藏  举报