給定一個整數 n,返回 n! 結果尾數中零的數量。
示例 1:
輸入: 3
輸出: 0
解釋:?3! = 6, 尾數中沒有零。
示例?2:
輸入: 5
輸出: 1
解釋:?5! = 120, 尾數中有 1 個零.
說明: 你算法的時間復雜度應為?O(log?n)?。
思路:10=2*5,而因數中2一定比5多,所以我們找5的個數即可。
public int trailingZeroes(int n) {int count = 0;while (n > 0) {count += n / 5;n = n / 5;}return count;
}
?