p172 发表于 2017-02-15 | 分类于 blog | LeetCode p172 Factorial Trailing Zeroes 题解1.题目: Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 题意: 输入n输出n的阶乘的末尾有多少个0. 2.解题思路: 10=2×5由于2比5多。所以统计因子中所有的5. 3.代码 [title] [] [url] [link text]1234567891011 public class Solution { public int trailingZeroes(int n) { int ans = 0; while (n > 4) { ans = ans + n / 5; n = n / 5; } return ans; }} 4.一些总结: