标签:
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
Solution :计算包含的2和5组成的pair的个数,因为5的个数比2少,所以2和5组成的pair的个数由5的个数决定。
1 class Solution { 2 public: 3 int trailingZeroes(int n) { 4 int ret=0; 5 while(n){ 6 ret += n/5; 7 n /= 5; 8 } 9 return ret; 10 } 11 };
【LeetCode】172 - Factorial Trailing Zeroes
标签:
原文地址:http://www.cnblogs.com/irun/p/4705421.html